-- [Re-Write] Removed nearly everything, and started from scratch.
The reason for doing this? Got an idea for gameplay, and what I previusly wrote did not fit, and it sucked anyhow. Let's play.
This commit is contained in:
		
							parent
							
								
									8494e35d31
								
							
						
					
					
						commit
						fe6ccf46d9
					
				
							
								
								
									
										
											BIN
										
									
								
								Unuk-QT/Entity.o
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										
											BIN
										
									
								
								Unuk-QT/Entity.o
									
									
									
									
									
										Normal file
									
								
							
										
											Binary file not shown.
										
									
								
							
							
								
								
									
										
											BIN
										
									
								
								Unuk-QT/Game.o
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										
											BIN
										
									
								
								Unuk-QT/Game.o
									
									
									
									
									
										Normal file
									
								
							
										
											Binary file not shown.
										
									
								
							
							
								
								
									
										
											BIN
										
									
								
								Unuk-QT/ImageLoader.o
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										
											BIN
										
									
								
								Unuk-QT/ImageLoader.o
									
									
									
									
									
										Normal file
									
								
							
										
											Binary file not shown.
										
									
								
							@ -1,6 +1,6 @@
 | 
			
		||||
#############################################################################
 | 
			
		||||
# Makefile for building: Unuk-QT
 | 
			
		||||
# Generated by qmake (2.01a) (Qt 4.7.3) on: Tue Oct 25 22:14:31 2011
 | 
			
		||||
# Generated by qmake (2.01a) (Qt 4.7.3) on: Sun Nov 6 22:57:44 2011
 | 
			
		||||
# Project:  Unuk-QT.pro
 | 
			
		||||
# Template: app
 | 
			
		||||
# Command: /usr/bin/qmake-qt4 -spec /usr/share/qt4/mkspecs/linux-g++ CONFIG+=debug -o Makefile Unuk-QT.pro
 | 
			
		||||
@ -16,7 +16,7 @@ CXXFLAGS      = -pipe -g -Wall -W -D_REENTRANT $(DEFINES)
 | 
			
		||||
INCPATH       = -I/usr/share/qt4/mkspecs/linux-g++ -I. -I/usr/include/qt4/QtCore -I/usr/include/qt4/QtGui -I/usr/include/qt4 -I.
 | 
			
		||||
LINK          = g++
 | 
			
		||||
LFLAGS        = 
 | 
			
		||||
LIBS          = $(SUBLIBS)  -L/usr/lib -lGL -lSDL -lGLU -lQtGui -lQtCore -lpthread 
 | 
			
		||||
LIBS          = $(SUBLIBS)  -L/usr/lib -lGL -lSDL -lSDL_ttf -lGLU -lQtGui -lQtCore -lpthread 
 | 
			
		||||
AR            = ar cqs
 | 
			
		||||
RANLIB        = 
 | 
			
		||||
QMAKE         = /usr/bin/qmake-qt4
 | 
			
		||||
@ -43,26 +43,21 @@ OBJECTS_DIR   = ./
 | 
			
		||||
 | 
			
		||||
####### Files
 | 
			
		||||
 | 
			
		||||
SOURCES       = ../src/libUnuk/Sprite.cpp \
 | 
			
		||||
		../src/libUnuk/ImageLoader.cpp \
 | 
			
		||||
		../src/libUnuk/Debug.cpp \
 | 
			
		||||
		../src/Unuk/Player.cpp \
 | 
			
		||||
SOURCES       = ../src/libUnuk/Debug.cpp \
 | 
			
		||||
		../src/Unuk/main.cpp \
 | 
			
		||||
		../src/Unuk/Game.cpp \
 | 
			
		||||
		../src/libUnuk/Entity.cpp \
 | 
			
		||||
		../src/libUnuk/Input.cpp 
 | 
			
		||||
OBJECTS       = Sprite.o \
 | 
			
		||||
		ImageLoader.o \
 | 
			
		||||
		Debug.o \
 | 
			
		||||
		Player.o \
 | 
			
		||||
		../src/libUnuk/Input.cpp \
 | 
			
		||||
		../src/libUnuk/Timer.cpp \
 | 
			
		||||
		../src/libUnuk/Font.cpp 
 | 
			
		||||
OBJECTS       = Debug.o \
 | 
			
		||||
		main.o \
 | 
			
		||||
		Game.o \
 | 
			
		||||
		Entity.o \
 | 
			
		||||
		Input.o
 | 
			
		||||
		Input.o \
 | 
			
		||||
		Timer.o \
 | 
			
		||||
		Font.o
 | 
			
		||||
DIST          = /usr/share/qt4/mkspecs/common/g++.conf \
 | 
			
		||||
		/usr/share/qt4/mkspecs/common/unix.conf \
 | 
			
		||||
		/usr/share/qt4/mkspecs/common/linux.conf \
 | 
			
		||||
		/usr/share/qt4/mkspecs/qconfig.pri \
 | 
			
		||||
		/usr/share/qt4/mkspecs/modules/qt_phonon.pri \
 | 
			
		||||
		/usr/share/qt4/mkspecs/features/qt_functions.prf \
 | 
			
		||||
		/usr/share/qt4/mkspecs/features/qt_config.prf \
 | 
			
		||||
		/usr/share/qt4/mkspecs/features/exclusive_builds.prf \
 | 
			
		||||
@ -114,6 +109,7 @@ Makefile: Unuk-QT.pro  /usr/share/qt4/mkspecs/linux-g++/qmake.conf /usr/share/qt
 | 
			
		||||
		/usr/share/qt4/mkspecs/common/unix.conf \
 | 
			
		||||
		/usr/share/qt4/mkspecs/common/linux.conf \
 | 
			
		||||
		/usr/share/qt4/mkspecs/qconfig.pri \
 | 
			
		||||
		/usr/share/qt4/mkspecs/modules/qt_phonon.pri \
 | 
			
		||||
		/usr/share/qt4/mkspecs/features/qt_functions.prf \
 | 
			
		||||
		/usr/share/qt4/mkspecs/features/qt_config.prf \
 | 
			
		||||
		/usr/share/qt4/mkspecs/features/exclusive_builds.prf \
 | 
			
		||||
@ -136,6 +132,7 @@ Makefile: Unuk-QT.pro  /usr/share/qt4/mkspecs/linux-g++/qmake.conf /usr/share/qt
 | 
			
		||||
/usr/share/qt4/mkspecs/common/unix.conf:
 | 
			
		||||
/usr/share/qt4/mkspecs/common/linux.conf:
 | 
			
		||||
/usr/share/qt4/mkspecs/qconfig.pri:
 | 
			
		||||
/usr/share/qt4/mkspecs/modules/qt_phonon.pri:
 | 
			
		||||
/usr/share/qt4/mkspecs/features/qt_functions.prf:
 | 
			
		||||
/usr/share/qt4/mkspecs/features/qt_config.prf:
 | 
			
		||||
/usr/share/qt4/mkspecs/features/exclusive_builds.prf:
 | 
			
		||||
@ -158,7 +155,7 @@ qmake:  FORCE
 | 
			
		||||
 | 
			
		||||
dist: 
 | 
			
		||||
	@$(CHK_DIR_EXISTS) .tmp/Unuk-QT1.0.0 || $(MKDIR) .tmp/Unuk-QT1.0.0 
 | 
			
		||||
	$(COPY_FILE) --parents $(SOURCES) $(DIST) .tmp/Unuk-QT1.0.0/ && $(COPY_FILE) --parents ../src/libUnuk/ImageLoader.h ../src/libUnuk/Sprite.h ../src/libUnuk/Debug.h ../src/Libs/wglext.h ../src/Libs/glxext.h ../src/Unuk/Game.h ../src/Unuk/Player.h ../src/libUnuk/Static.h ../src/libUnuk/Geometry.h ../src/libUnuk/Entity.h ../src/libUnuk/EntityType.h ../src/libUnuk/Input.h .tmp/Unuk-QT1.0.0/ && $(COPY_FILE) --parents ../src/libUnuk/Sprite.cpp ../src/libUnuk/ImageLoader.cpp ../src/libUnuk/Debug.cpp ../src/Unuk/Player.cpp ../src/Unuk/main.cpp ../src/Unuk/Game.cpp ../src/libUnuk/Entity.cpp ../src/libUnuk/Input.cpp .tmp/Unuk-QT1.0.0/ && (cd `dirname .tmp/Unuk-QT1.0.0` && $(TAR) Unuk-QT1.0.0.tar Unuk-QT1.0.0 && $(COMPRESS) Unuk-QT1.0.0.tar) && $(MOVE) `dirname .tmp/Unuk-QT1.0.0`/Unuk-QT1.0.0.tar.gz . && $(DEL_FILE) -r .tmp/Unuk-QT1.0.0
 | 
			
		||||
	$(COPY_FILE) --parents $(SOURCES) $(DIST) .tmp/Unuk-QT1.0.0/ && $(COPY_FILE) --parents ../src/libUnuk/Debug.h ../src/Libs/wglext.h ../src/Libs/glxext.h ../src/libUnuk/Input.h ../src/libUnuk/Rect.h ../src/libUnuk/Timer.h ../src/libUnuk/Font.h ../Constants.h ../src/Unuk/Constants.h .tmp/Unuk-QT1.0.0/ && $(COPY_FILE) --parents ../src/libUnuk/Debug.cpp ../src/Unuk/main.cpp ../src/libUnuk/Input.cpp ../src/libUnuk/Timer.cpp ../src/libUnuk/Font.cpp .tmp/Unuk-QT1.0.0/ && (cd `dirname .tmp/Unuk-QT1.0.0` && $(TAR) Unuk-QT1.0.0.tar Unuk-QT1.0.0 && $(COMPRESS) Unuk-QT1.0.0.tar) && $(MOVE) `dirname .tmp/Unuk-QT1.0.0`/Unuk-QT1.0.0.tar.gz . && $(DEL_FILE) -r .tmp/Unuk-QT1.0.0
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
clean:compiler_clean 
 | 
			
		||||
@ -200,50 +197,24 @@ compiler_clean:
 | 
			
		||||
 | 
			
		||||
####### Compile
 | 
			
		||||
 | 
			
		||||
Sprite.o: ../src/libUnuk/Sprite.cpp ../src/libUnuk/Sprite.h \
 | 
			
		||||
		../src/libUnuk/ImageLoader.h \
 | 
			
		||||
		../src/libUnuk/Debug.h
 | 
			
		||||
	$(CXX) -c $(CXXFLAGS) $(INCPATH) -o Sprite.o ../src/libUnuk/Sprite.cpp
 | 
			
		||||
 | 
			
		||||
ImageLoader.o: ../src/libUnuk/ImageLoader.cpp ../src/libUnuk/ImageLoader.h \
 | 
			
		||||
		../src/libUnuk/Debug.h
 | 
			
		||||
	$(CXX) -c $(CXXFLAGS) $(INCPATH) -o ImageLoader.o ../src/libUnuk/ImageLoader.cpp
 | 
			
		||||
 | 
			
		||||
Debug.o: ../src/libUnuk/Debug.cpp ../src/libUnuk/Debug.h
 | 
			
		||||
	$(CXX) -c $(CXXFLAGS) $(INCPATH) -o Debug.o ../src/libUnuk/Debug.cpp
 | 
			
		||||
 | 
			
		||||
Player.o: ../src/Unuk/Player.cpp ../src/libUnuk/Sprite.h \
 | 
			
		||||
		../src/libUnuk/ImageLoader.h \
 | 
			
		||||
main.o: ../src/Unuk/main.cpp ../src/libUnuk/Input.h \
 | 
			
		||||
		../src/libUnuk/Debug.h \
 | 
			
		||||
		../src/libUnuk/Input.h \
 | 
			
		||||
		../src/Unuk/Player.h
 | 
			
		||||
	$(CXX) -c $(CXXFLAGS) $(INCPATH) -o Player.o ../src/Unuk/Player.cpp
 | 
			
		||||
 | 
			
		||||
main.o: ../src/Unuk/main.cpp ../src/Unuk/Game.h \
 | 
			
		||||
		../src/Unuk/Player.h \
 | 
			
		||||
		../src/libUnuk/Sprite.h \
 | 
			
		||||
		../src/libUnuk/ImageLoader.h \
 | 
			
		||||
		../src/libUnuk/Input.h \
 | 
			
		||||
		../src/libUnuk/Debug.h
 | 
			
		||||
		../src/Unuk/Constants.h
 | 
			
		||||
	$(CXX) -c $(CXXFLAGS) $(INCPATH) -o main.o ../src/Unuk/main.cpp
 | 
			
		||||
 | 
			
		||||
Game.o: ../src/Unuk/Game.cpp ../src/Unuk/Game.h \
 | 
			
		||||
		../src/Unuk/Player.h \
 | 
			
		||||
		../src/libUnuk/Sprite.h \
 | 
			
		||||
		../src/libUnuk/ImageLoader.h \
 | 
			
		||||
		../src/libUnuk/Input.h \
 | 
			
		||||
		../src/libUnuk/Debug.h
 | 
			
		||||
	$(CXX) -c $(CXXFLAGS) $(INCPATH) -o Game.o ../src/Unuk/Game.cpp
 | 
			
		||||
 | 
			
		||||
Entity.o: ../src/libUnuk/Entity.cpp ../src/libUnuk/Entity.h \
 | 
			
		||||
		../src/libUnuk/Geometry.h \
 | 
			
		||||
		../src/libUnuk/EntityType.h \
 | 
			
		||||
		../src/libUnuk/Static.h
 | 
			
		||||
	$(CXX) -c $(CXXFLAGS) $(INCPATH) -o Entity.o ../src/libUnuk/Entity.cpp
 | 
			
		||||
 | 
			
		||||
Input.o: ../src/libUnuk/Input.cpp ../src/libUnuk/Input.h
 | 
			
		||||
	$(CXX) -c $(CXXFLAGS) $(INCPATH) -o Input.o ../src/libUnuk/Input.cpp
 | 
			
		||||
 | 
			
		||||
Timer.o: ../src/libUnuk/Timer.cpp ../src/libUnuk/Timer.h
 | 
			
		||||
	$(CXX) -c $(CXXFLAGS) $(INCPATH) -o Timer.o ../src/libUnuk/Timer.cpp
 | 
			
		||||
 | 
			
		||||
Font.o: ../src/libUnuk/Font.cpp ../src/libUnuk/Font.h \
 | 
			
		||||
		../src/libUnuk/Debug.h
 | 
			
		||||
	$(CXX) -c $(CXXFLAGS) $(INCPATH) -o Font.o ../src/libUnuk/Font.cpp
 | 
			
		||||
 | 
			
		||||
####### Install
 | 
			
		||||
 | 
			
		||||
install:   FORCE
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										
											BIN
										
									
								
								Unuk-QT/Player.o
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										
											BIN
										
									
								
								Unuk-QT/Player.o
									
									
									
									
									
										Normal file
									
								
							
										
											Binary file not shown.
										
									
								
							
							
								
								
									
										
											BIN
										
									
								
								Unuk-QT/Sprite.o
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										
											BIN
										
									
								
								Unuk-QT/Sprite.o
									
									
									
									
									
										Normal file
									
								
							
										
											Binary file not shown.
										
									
								
							@ -1,29 +1,20 @@
 | 
			
		||||
LIBS += -lGL \
 | 
			
		||||
    -lSDL \
 | 
			
		||||
    -lSDL_ttf \
 | 
			
		||||
    -lGLU
 | 
			
		||||
RESOURCES += 
 | 
			
		||||
OTHER_FILES += ../src/libUnuk/Vec2.o \
 | 
			
		||||
    ../src/libUnuk/ImageLoader.o \
 | 
			
		||||
    ../src/libUnuk/GlxWindow.o \
 | 
			
		||||
    ../src/libUnuk/Sprite.o \
 | 
			
		||||
    ../src/libUnuk/Debug.o
 | 
			
		||||
HEADERS += ../src/libUnuk/ImageLoader.h \
 | 
			
		||||
    ../src/libUnuk/Sprite.h \
 | 
			
		||||
    ../src/libUnuk/Debug.h \
 | 
			
		||||
OTHER_FILES += ../src/libUnuk/Debug.o
 | 
			
		||||
HEADERS += ../src/libUnuk/Debug.h \
 | 
			
		||||
    ../src/Libs/wglext.h \
 | 
			
		||||
    ../src/Libs/glxext.h \
 | 
			
		||||
    ../src/Unuk/Game.h \
 | 
			
		||||
    ../src/Unuk/Player.h \
 | 
			
		||||
    ../src/libUnuk/Static.h \
 | 
			
		||||
    ../src/libUnuk/Geometry.h \
 | 
			
		||||
    ../src/libUnuk/Entity.h \
 | 
			
		||||
    ../src/libUnuk/EntityType.h \
 | 
			
		||||
    ../src/libUnuk/Input.h
 | 
			
		||||
SOURCES += ../src/libUnuk/Sprite.cpp \
 | 
			
		||||
    ../src/libUnuk/ImageLoader.cpp \
 | 
			
		||||
    ../src/libUnuk/Debug.cpp \
 | 
			
		||||
    ../src/Unuk/Player.cpp \
 | 
			
		||||
    ../src/libUnuk/Input.h \
 | 
			
		||||
    ../src/libUnuk/Rect.h \
 | 
			
		||||
    ../src/libUnuk/Timer.h \
 | 
			
		||||
    ../src/libUnuk/Font.h \
 | 
			
		||||
    ../Constants.h \
 | 
			
		||||
    ../src/Unuk/Constants.h
 | 
			
		||||
SOURCES += ../src/libUnuk/Debug.cpp \
 | 
			
		||||
    ../src/Unuk/main.cpp \
 | 
			
		||||
    ../src/Unuk/Game.cpp \
 | 
			
		||||
    ../src/libUnuk/Entity.cpp \
 | 
			
		||||
    ../src/libUnuk/Input.cpp
 | 
			
		||||
    ../src/libUnuk/Input.cpp \
 | 
			
		||||
    ../src/libUnuk/Timer.cpp \
 | 
			
		||||
    ../src/libUnuk/Font.cpp
 | 
			
		||||
 | 
			
		||||
@ -76,7 +76,7 @@
 | 
			
		||||
  <valuemap type="QVariantMap">
 | 
			
		||||
   <value key="ProjectExplorer.BuildConfiguration.DisplayName" type="QString">Debug</value>
 | 
			
		||||
   <valuelist key="abstractProcess.Environment" type="QVariantList">
 | 
			
		||||
    <value type="QString">DBUS_SESSION_BUS_ADDRESS=unix:abstract=/tmp/dbus-KIZOCtJ0Qj,guid=2d6e4614e1a8d0c60ff1566700000052</value>
 | 
			
		||||
    <value type="QString">DBUS_SESSION_BUS_ADDRESS=unix:abstract=/tmp/dbus-PlNAR2DRhi,guid=647dcd2f857df095e9fb55f200000037</value>
 | 
			
		||||
    <value type="QString">DISPLAY=:0</value>
 | 
			
		||||
    <value type="QString">HOME=/home/allanis</value>
 | 
			
		||||
    <value type="QString">HUSHLOGIN=FALSE</value>
 | 
			
		||||
@ -89,13 +89,13 @@
 | 
			
		||||
    <value type="QString">QTDIR=/usr/share/qt4</value>
 | 
			
		||||
    <value type="QString">SHELL=/bin/bash</value>
 | 
			
		||||
    <value type="QString">SHLVL=1</value>
 | 
			
		||||
    <value type="QString">SSH_AGENT_PID=3289</value>
 | 
			
		||||
    <value type="QString">SSH_AUTH_SOCK=/tmp/ssh-bmvArYgf3264/agent.3264</value>
 | 
			
		||||
    <value type="QString">SSH_AGENT_PID=3247</value>
 | 
			
		||||
    <value type="QString">SSH_AUTH_SOCK=/tmp/ssh-aXmQFZXr3222/agent.3222</value>
 | 
			
		||||
    <value type="QString">TERM=linux</value>
 | 
			
		||||
    <value type="QString">USER=allanis</value>
 | 
			
		||||
    <value type="QString">WINDOWPATH=7</value>
 | 
			
		||||
    <value type="QString">XAUTHORITY=/home/allanis/.Xauthority</value>
 | 
			
		||||
    <value type="QString">XDG_SESSION_COOKIE=6de6dd7b78e791242262c6460000012e-1319816808.532592-2012073557</value>
 | 
			
		||||
    <value type="QString">XDG_SESSION_COOKIE=6de6dd7b78e791242262c6460000012e-1320507013.488131-497740237</value>
 | 
			
		||||
    <value type="QString">_=/usr/bin/startx</value>
 | 
			
		||||
   </valuelist>
 | 
			
		||||
   <valuelist key="abstractProcess.arguments" type="QVariantList">
 | 
			
		||||
@ -115,7 +115,7 @@
 | 
			
		||||
  <valuemap type="QVariantMap">
 | 
			
		||||
   <value key="ProjectExplorer.BuildConfiguration.DisplayName" type="QString">Debug</value>
 | 
			
		||||
   <valuelist key="abstractProcess.Environment" type="QVariantList">
 | 
			
		||||
    <value type="QString">DBUS_SESSION_BUS_ADDRESS=unix:abstract=/tmp/dbus-KIZOCtJ0Qj,guid=2d6e4614e1a8d0c60ff1566700000052</value>
 | 
			
		||||
    <value type="QString">DBUS_SESSION_BUS_ADDRESS=unix:abstract=/tmp/dbus-PlNAR2DRhi,guid=647dcd2f857df095e9fb55f200000037</value>
 | 
			
		||||
    <value type="QString">DISPLAY=:0</value>
 | 
			
		||||
    <value type="QString">HOME=/home/allanis</value>
 | 
			
		||||
    <value type="QString">HUSHLOGIN=FALSE</value>
 | 
			
		||||
@ -128,13 +128,13 @@
 | 
			
		||||
    <value type="QString">QTDIR=/usr/share/qt4</value>
 | 
			
		||||
    <value type="QString">SHELL=/bin/bash</value>
 | 
			
		||||
    <value type="QString">SHLVL=1</value>
 | 
			
		||||
    <value type="QString">SSH_AGENT_PID=3289</value>
 | 
			
		||||
    <value type="QString">SSH_AUTH_SOCK=/tmp/ssh-bmvArYgf3264/agent.3264</value>
 | 
			
		||||
    <value type="QString">SSH_AGENT_PID=3247</value>
 | 
			
		||||
    <value type="QString">SSH_AUTH_SOCK=/tmp/ssh-aXmQFZXr3222/agent.3222</value>
 | 
			
		||||
    <value type="QString">TERM=linux</value>
 | 
			
		||||
    <value type="QString">USER=allanis</value>
 | 
			
		||||
    <value type="QString">WINDOWPATH=7</value>
 | 
			
		||||
    <value type="QString">XAUTHORITY=/home/allanis/.Xauthority</value>
 | 
			
		||||
    <value type="QString">XDG_SESSION_COOKIE=6de6dd7b78e791242262c6460000012e-1319816808.532592-2012073557</value>
 | 
			
		||||
    <value type="QString">XDG_SESSION_COOKIE=6de6dd7b78e791242262c6460000012e-1320507013.488131-497740237</value>
 | 
			
		||||
    <value type="QString">_=/usr/bin/startx</value>
 | 
			
		||||
   </valuelist>
 | 
			
		||||
   <value key="abstractProcess.IgnoreReturnValue" type="bool">false</value>
 | 
			
		||||
@ -151,7 +151,7 @@
 | 
			
		||||
  <valuemap type="QVariantMap">
 | 
			
		||||
   <value key="ProjectExplorer.BuildConfiguration.DisplayName" type="QString">Debug</value>
 | 
			
		||||
   <valuelist key="abstractProcess.Environment" type="QVariantList">
 | 
			
		||||
    <value type="QString">DBUS_SESSION_BUS_ADDRESS=unix:abstract=/tmp/dbus-KIZOCtJ0Qj,guid=2d6e4614e1a8d0c60ff1566700000052</value>
 | 
			
		||||
    <value type="QString">DBUS_SESSION_BUS_ADDRESS=unix:abstract=/tmp/dbus-PlNAR2DRhi,guid=647dcd2f857df095e9fb55f200000037</value>
 | 
			
		||||
    <value type="QString">DISPLAY=:0</value>
 | 
			
		||||
    <value type="QString">HOME=/home/allanis</value>
 | 
			
		||||
    <value type="QString">HUSHLOGIN=FALSE</value>
 | 
			
		||||
@ -164,13 +164,13 @@
 | 
			
		||||
    <value type="QString">QTDIR=/usr/share/qt4</value>
 | 
			
		||||
    <value type="QString">SHELL=/bin/bash</value>
 | 
			
		||||
    <value type="QString">SHLVL=1</value>
 | 
			
		||||
    <value type="QString">SSH_AGENT_PID=3289</value>
 | 
			
		||||
    <value type="QString">SSH_AUTH_SOCK=/tmp/ssh-bmvArYgf3264/agent.3264</value>
 | 
			
		||||
    <value type="QString">SSH_AGENT_PID=3247</value>
 | 
			
		||||
    <value type="QString">SSH_AUTH_SOCK=/tmp/ssh-aXmQFZXr3222/agent.3222</value>
 | 
			
		||||
    <value type="QString">TERM=linux</value>
 | 
			
		||||
    <value type="QString">USER=allanis</value>
 | 
			
		||||
    <value type="QString">WINDOWPATH=7</value>
 | 
			
		||||
    <value type="QString">XAUTHORITY=/home/allanis/.Xauthority</value>
 | 
			
		||||
    <value type="QString">XDG_SESSION_COOKIE=6de6dd7b78e791242262c6460000012e-1319816808.532592-2012073557</value>
 | 
			
		||||
    <value type="QString">XDG_SESSION_COOKIE=6de6dd7b78e791242262c6460000012e-1320507013.488131-497740237</value>
 | 
			
		||||
    <value type="QString">_=/usr/bin/startx</value>
 | 
			
		||||
   </valuelist>
 | 
			
		||||
   <value key="abstractProcess.IgnoreReturnValue" type="bool">true</value>
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										15
									
								
								src/Unuk/Constants.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										15
									
								
								src/Unuk/Constants.h
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,15 @@
 | 
			
		||||
#ifndef _CONSTANTS_H_
 | 
			
		||||
#define _CONSTANTS_H_
 | 
			
		||||
#include <SDL/SDL.h>
 | 
			
		||||
 | 
			
		||||
const int TILE_WIDTH  = 64;
 | 
			
		||||
const int TILE_HEIGHT = 64;
 | 
			
		||||
 | 
			
		||||
const int SCREEN_WIDTH  = 640;
 | 
			
		||||
const int SCREEN_HEIGHT = 480;
 | 
			
		||||
const int SCREEN_BPP    = 16;
 | 
			
		||||
 | 
			
		||||
const SDL_Color COLOUR_BLACK = { 0, 0, 0 };
 | 
			
		||||
const SDL_Color COLOUR_WHITE = { 255, 255, 255 };
 | 
			
		||||
 | 
			
		||||
#endif
 | 
			
		||||
@ -1,145 +0,0 @@
 | 
			
		||||
#ifdef WIN32
 | 
			
		||||
#include <windows.h>
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
#include <X11/Xlib.h>
 | 
			
		||||
#include <GL/gl.h>
 | 
			
		||||
#include <GL/glu.h>
 | 
			
		||||
#include <GL/glut.h>
 | 
			
		||||
#include <cstdlib>
 | 
			
		||||
 | 
			
		||||
#include "SDL/SDL.h"
 | 
			
		||||
#include "Game.h"
 | 
			
		||||
#include "Player.h"
 | 
			
		||||
#include "../libUnuk/Input.h"
 | 
			
		||||
#include "../libUnuk/Sprite.h"
 | 
			
		||||
#include "../libUnuk/Debug.h"
 | 
			
		||||
 | 
			
		||||
Game::Game(void) {
 | 
			
		||||
  m_assets = false;
 | 
			
		||||
  m_rotationAngle = 0.0f;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
Game::~Game(void) {
 | 
			
		||||
  DeleteAssets();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
bool Game::Init(void) {
 | 
			
		||||
  LoadAssets();
 | 
			
		||||
  glEnable(GL_DEPTH_TEST);
 | 
			
		||||
  glDepthFunc(GL_LEQUAL);
 | 
			
		||||
  m_assets = true;
 | 
			
		||||
  return true;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void Game::Prepare(float dt) {
 | 
			
		||||
  glEnable(GL_BLEND);
 | 
			
		||||
  glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
 | 
			
		||||
  glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
 | 
			
		||||
  glShadeModel(GL_FLAT);
 | 
			
		||||
  glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
 | 
			
		||||
 | 
			
		||||
  Sprite::Enable2D();
 | 
			
		||||
 | 
			
		||||
  m_player->Prepare();
 | 
			
		||||
 | 
			
		||||
  const float SPEED = 15.0f;
 | 
			
		||||
  m_rotationAngle += SPEED * dt;
 | 
			
		||||
  if(m_rotationAngle > 360.0f) {
 | 
			
		||||
    m_rotationAngle -= 360.0f;
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void Game::Render(void) {
 | 
			
		||||
  static GLint T0	= 0;
 | 
			
		||||
  static GLint frames	= 0;
 | 
			
		||||
 | 
			
		||||
  glClear(GL_COLOR_BUFFER_BIT);
 | 
			
		||||
  glRasterPos2i(0, 0);
 | 
			
		||||
 | 
			
		||||
  // Draw the test image.
 | 
			
		||||
  if(m_assets) {
 | 
			
		||||
    m_player->Render();
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  glFlush();
 | 
			
		||||
 | 
			
		||||
  glDisable(GL_TEXTURE_2D);
 | 
			
		||||
 | 
			
		||||
  // Get frames per second.
 | 
			
		||||
  frames++;
 | 
			
		||||
  {
 | 
			
		||||
    GLint t = SDL_GetTicks();
 | 
			
		||||
    if (t - T0 >= 5000) {
 | 
			
		||||
      GLfloat seconds = (t - T0) / 1000.0f;
 | 
			
		||||
      GLfloat fps = frames / seconds;
 | 
			
		||||
      Debug::logger->message("\n%d frames in %g seconds = %g FPS", frames, seconds, fps);
 | 
			
		||||
      T0 = t;
 | 
			
		||||
      frames = 0;
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
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( 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) {
 | 
			
		||||
  // Let's see you divide by zero now!
 | 
			
		||||
  if(height == 0) { height = 1; }
 | 
			
		||||
 | 
			
		||||
  // Set the viewport to the window size.
 | 
			
		||||
  glViewport(0, 0, width, height);
 | 
			
		||||
 | 
			
		||||
  // Set the projection.
 | 
			
		||||
  UpdateProjection();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void Game::LoadAssets(void) {
 | 
			
		||||
  m_player = new Player();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void Game::DeleteAssets(void) {
 | 
			
		||||
  delete m_player;
 | 
			
		||||
}
 | 
			
		||||
@ -1,30 +0,0 @@
 | 
			
		||||
#ifndef _GAME_H_
 | 
			
		||||
#define _GAME_H_
 | 
			
		||||
#include "SDL/SDL.h"
 | 
			
		||||
#include "Player.h"
 | 
			
		||||
 | 
			
		||||
class Game {
 | 
			
		||||
public:
 | 
			
		||||
  Game(void);
 | 
			
		||||
  ~Game(void);
 | 
			
		||||
 | 
			
		||||
  bool Init(void);
 | 
			
		||||
  void Prepare(float dt);
 | 
			
		||||
  void Render(void);
 | 
			
		||||
  void Shutdown(void);
 | 
			
		||||
 | 
			
		||||
  void UpdateProjection();
 | 
			
		||||
  void OnResize(int width, int height);
 | 
			
		||||
 | 
			
		||||
  bool IsInit(void) { return m_assets; }
 | 
			
		||||
 | 
			
		||||
private:
 | 
			
		||||
  void LoadAssets(void);
 | 
			
		||||
  void DeleteAssets(void);
 | 
			
		||||
  float m_rotationAngle;
 | 
			
		||||
  Player *m_player;
 | 
			
		||||
 | 
			
		||||
  bool m_assets;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
#endif 
 | 
			
		||||
@ -2,7 +2,7 @@ CC	= g++
 | 
			
		||||
CFLAGS	= -ansi -Wall -g
 | 
			
		||||
LDADD	= -lGL -lGLU -lSDL -lSDL_image
 | 
			
		||||
 | 
			
		||||
objects = Game.o Player.o
 | 
			
		||||
objects = 
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
.PHONY: default all clean
 | 
			
		||||
 | 
			
		||||
@ -1,63 +0,0 @@
 | 
			
		||||
#include <GL/gl.h>
 | 
			
		||||
#include <SDL/SDL.h>
 | 
			
		||||
#include "../libUnuk/Sprite.h"
 | 
			
		||||
#include "../libUnuk/Debug.h"
 | 
			
		||||
#include "../libUnuk/Input.h"
 | 
			
		||||
#include "Player.h"
 | 
			
		||||
 | 
			
		||||
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) {
 | 
			
		||||
  // 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.
 | 
			
		||||
  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); }
 | 
			
		||||
  UpdateInput();
 | 
			
		||||
 | 
			
		||||
  SetPosition(m_posx, m_posy);  
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void Player::Render(void) {
 | 
			
		||||
  // Only render calls should appear here.
 | 
			
		||||
  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.
 | 
			
		||||
  m_posx = posx;
 | 
			
		||||
  m_posy = posy;
 | 
			
		||||
 | 
			
		||||
  m_player->SetX(m_posx);
 | 
			
		||||
  m_player->SetY(m_posy);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void Player::SetVelocity(GLdouble velx, GLdouble vely) {
 | 
			
		||||
  m_velx = velx;
 | 
			
		||||
  m_vely = vely;
 | 
			
		||||
 | 
			
		||||
  m_posx += m_velx;
 | 
			
		||||
  m_posy += m_vely;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void Player::CleanUp(void) {
 | 
			
		||||
  delete m_player;
 | 
			
		||||
}
 | 
			
		||||
@ -1,33 +0,0 @@
 | 
			
		||||
#ifndef _PLAYER_H_
 | 
			
		||||
#define _PLAYER_H_
 | 
			
		||||
#include <SDL/SDL.h>
 | 
			
		||||
#include "../libUnuk/Sprite.h"
 | 
			
		||||
 | 
			
		||||
class Player {
 | 
			
		||||
public:
 | 
			
		||||
  Player(void);
 | 
			
		||||
  ~Player(void);
 | 
			
		||||
 | 
			
		||||
  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;
 | 
			
		||||
 | 
			
		||||
  // Position variables.
 | 
			
		||||
  GLdouble m_posx;
 | 
			
		||||
  GLdouble m_posy;
 | 
			
		||||
 | 
			
		||||
  // Velocity variables.
 | 
			
		||||
  int m_velx;
 | 
			
		||||
  int m_vely;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
#endif
 | 
			
		||||
@ -7,14 +7,14 @@
 | 
			
		||||
#include <GL/gl.h>
 | 
			
		||||
#include <GL/glu.h>
 | 
			
		||||
#include "SDL/SDL.h"
 | 
			
		||||
#include "Game.h"
 | 
			
		||||
#include "../libUnuk/Input.h"
 | 
			
		||||
#include "../libUnuk/Debug.h"
 | 
			
		||||
#include "Constants.h"
 | 
			
		||||
 | 
			
		||||
// Screen width, height, and bit depth.
 | 
			
		||||
const int SCREEN_WIDTH  = 640;
 | 
			
		||||
const int SCREEN_HEIGHT = 480;
 | 
			
		||||
const int SCREEN_BPP    = 16;
 | 
			
		||||
//const int SCREEN_WIDTH  = 640;
 | 
			
		||||
//const int SCREEN_HEIGHT = 480;
 | 
			
		||||
//const int SCREEN_BPP    = 16;
 | 
			
		||||
 | 
			
		||||
// Define our SDL surface.
 | 
			
		||||
SDL_Surface *surface;
 | 
			
		||||
@ -120,7 +120,6 @@ int main() {
 | 
			
		||||
  bool done = false;
 | 
			
		||||
  SDL_Event event;
 | 
			
		||||
  const SDL_VideoInfo *videoInfo;
 | 
			
		||||
  Game game;
 | 
			
		||||
 | 
			
		||||
  // Initialize SDL.
 | 
			
		||||
  if(SDL_Init(SDL_INIT_VIDEO) < 0) {
 | 
			
		||||
@ -170,8 +169,6 @@ int main() {
 | 
			
		||||
  // Initialize OpenGL.
 | 
			
		||||
  InitGL();
 | 
			
		||||
 | 
			
		||||
  Debug::logger->message("Game Initialize!");
 | 
			
		||||
 | 
			
		||||
  Debug::logger->message("\n\n-----Engine Initialization Complete-----");
 | 
			
		||||
  Debug::logger->message("\n\n-----Logic-----");
 | 
			
		||||
 | 
			
		||||
@ -204,13 +201,7 @@ int main() {
 | 
			
		||||
    }
 | 
			
		||||
    // Render the scene.
 | 
			
		||||
    float elapsedTime = GetElapsedSeconds();
 | 
			
		||||
    //game.ProcessEvents();
 | 
			
		||||
    //game.Init();
 | 
			
		||||
    if(!game.IsInit()) {
 | 
			
		||||
      game.Init();
 | 
			
		||||
    }
 | 
			
		||||
    game.Prepare(elapsedTime);
 | 
			
		||||
    game.Render();
 | 
			
		||||
 | 
			
		||||
    SDL_GL_SwapBuffers();
 | 
			
		||||
  }
 | 
			
		||||
  //game.Shutdown();
 | 
			
		||||
 | 
			
		||||
@ -1,289 +0,0 @@
 | 
			
		||||
#include <stdlib.h>
 | 
			
		||||
#include "AStar.h"
 | 
			
		||||
#include "Node.h"
 | 
			
		||||
 | 
			
		||||
AStar::AStar(void) {
 | 
			
		||||
  m_open    	  = NULL;
 | 
			
		||||
  m_stack  	  = NULL;
 | 
			
		||||
  m_best    	  = NULL;
 | 
			
		||||
  
 | 
			
		||||
  udCost    	  = NULL;
 | 
			
		||||
  udValid   	  = NULL;
 | 
			
		||||
  udNotifyChild   = NULL;  
 | 
			
		||||
  udNotifyList	  = NULL;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
AStar::~AStar(void) {
 | 
			
		||||
  ClearNodes();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
bool AStar::GeneratePath(int startx, int starty, int destx, int desty) {
 | 
			
		||||
  // Grab the next node from the f position.
 | 
			
		||||
  InitStep(startx, starty, destx, desty);
 | 
			
		||||
 | 
			
		||||
  int retval = 0;
 | 
			
		||||
  while(retval == 0) {
 | 
			
		||||
    // Go find the next node.
 | 
			
		||||
    retval = Step();
 | 
			
		||||
  }
 | 
			
		||||
  
 | 
			
		||||
  if(retval == 0 || !m_best) {
 | 
			
		||||
    // Set m_best to NULL so we can go and check for the next best node.
 | 
			
		||||
    m_best = NULL;
 | 
			
		||||
    return false;
 | 
			
		||||
  }
 | 
			
		||||
  return true;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
int AStar::Step(void) {
 | 
			
		||||
  // If we don't get the most efficent route, then go back
 | 
			
		||||
  // and check some more nodes plox!
 | 
			
		||||
  if(!(m_best == GetBest())) { return -1; }
 | 
			
		||||
  // Ok, we found the best route.
 | 
			
		||||
  if(m_best->id  == m_ID)    { return 1; }
 | 
			
		||||
  
 | 
			
		||||
  // Please set the best route as a child node.
 | 
			
		||||
  CreateChildren(m_best);
 | 
			
		||||
 
 | 
			
		||||
  return 0;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
int AStar::InitStep(int startx, int starty, int destx, int desty) {
 | 
			
		||||
  // Prepare for the next pass by clearing our previous nodes.
 | 
			
		||||
  ClearNodes();
 | 
			
		||||
  
 | 
			
		||||
  // Initialize our variables.
 | 
			
		||||
  m_startx = startx;
 | 
			
		||||
  m_starty = starty;
 | 
			
		||||
  m_destx  = destx;
 | 
			
		||||
  m_desty  = desty;
 | 
			
		||||
  m_ID = Coord2Id(destx, desty);
 | 
			
		||||
 
 | 
			
		||||
  // Set the node for our start location.
 | 
			
		||||
  Node *temp = new Node(startx, starty);
 | 
			
		||||
  temp->g = 0;
 | 
			
		||||
  temp->h = abs(destx - startx) + abs(desty - starty);
 | 
			
		||||
  temp->f = temp->g + temp->h;
 | 
			
		||||
  temp->id = Coord2Id(startx, starty);
 | 
			
		||||
  m_open = temp;
 | 
			
		||||
 | 
			
		||||
  return 0;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void AStar::AddToOpen(Node *addnode) {
 | 
			
		||||
  Node *node = m_open;
 | 
			
		||||
  Node *prev = NULL;
 | 
			
		||||
  
 | 
			
		||||
  if(!m_open) {
 | 
			
		||||
    // Add a a new node to the open list.
 | 
			
		||||
    m_open = addnode;
 | 
			
		||||
  
 | 
			
		||||
    m_open->next = NULL;
 | 
			
		||||
 | 
			
		||||
    // Start a new open list with our new node.
 | 
			
		||||
    //Func(udNotifyList, NULL, addnode, NL_STARTOPEN, NCData);
 | 
			
		||||
 
 | 
			
		||||
    return;
 | 
			
		||||
  }
 | 
			
		||||
  
 | 
			
		||||
  while(node) {
 | 
			
		||||
    // If our addnode's f is greater than the currently open node
 | 
			
		||||
    // then add the open node to the to previous to make room for
 | 
			
		||||
    // add node to be on the open list.
 | 
			
		||||
    if(addnode->f > node->f) {
 | 
			
		||||
      prev = node;
 | 
			
		||||
      // Now we have our new node go to next.
 | 
			
		||||
      node = node->next;
 | 
			
		||||
    } else {
 | 
			
		||||
      // go to the next node, and set it on our open list to check it's
 | 
			
		||||
      // f value.
 | 
			
		||||
      if(prev) {
 | 
			
		||||
        prev->next = addnode;
 | 
			
		||||
        addnode->next = node;
 | 
			
		||||
        Func(udNotifyList, prev, addnode, NL_ADDOPEN, NCData);
 | 
			
		||||
      } else {
 | 
			
		||||
        // We will only ever run through this once per instance. We have no nodes currently
 | 
			
		||||
	// so we set an open list with this node.
 | 
			
		||||
        Node *temp = m_open;
 | 
			
		||||
      
 | 
			
		||||
        m_open = addnode;
 | 
			
		||||
        m_open->next = temp;
 | 
			
		||||
        //Func(udNotifyList, temp, addnode, NL_STARTOPEN, NCData);
 | 
			
		||||
      } 
 | 
			
		||||
      return;
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
  // Get the next node and add it to the open list.
 | 
			
		||||
  prev->next = addnode;
 | 
			
		||||
  //Func(udNotifyList, prev, addnode, NL_ADDOPEN, NCData);              
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void AStar::ClearNodes(void) {
 | 
			
		||||
  Node *temp  = NULL;
 | 
			
		||||
  Node *temp2 = NULL;
 | 
			
		||||
  
 | 
			
		||||
  if(m_open) {
 | 
			
		||||
    while(m_open) {
 | 
			
		||||
      temp = m_open->next;
 | 
			
		||||
      delete m_open;
 | 
			
		||||
      m_open = temp;
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
  if(m_closed) {
 | 
			
		||||
    while(m_closed) {
 | 
			
		||||
      temp = m_closed->next;
 | 
			
		||||
      delete m_closed;
 | 
			
		||||
      m_closed = temp;
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void AStar::CreateChildren(Node *node) {
 | 
			
		||||
  Node temp;
 | 
			
		||||
  int x = node->x;
 | 
			
		||||
  int y = node->y;
 | 
			
		||||
 
 | 
			
		||||
  // Loop through the grid and add the children to the list.
 | 
			
		||||
  for(int i = -1; i < 2; i++) {
 | 
			
		||||
    for(int j = -1; j < 2; j++) {
 | 
			
		||||
      temp.x = x+i;
 | 
			
		||||
      temp.y = y+j;
 | 
			
		||||
      if((i == 0) && (j == 0) || !Func(udValid, node, &temp, NC_INITIALADD, CBData)) continue;
 | 
			
		||||
	
 | 
			
		||||
      LinkChild(node, &temp);
 | 
			
		||||
    }
 | 
			
		||||
  }	
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void AStar::LinkChild(Node *node, Node *temp) {
 | 
			
		||||
  // Initialize variables for our temp node.
 | 
			
		||||
  int x = temp->x;
 | 
			
		||||
  int y = temp->y;
 | 
			
		||||
  int g = temp->g + Func(udCost, node, temp, 0, CBData);
 | 
			
		||||
  // Grabbing a unique ID before adding the node to the open list.
 | 
			
		||||
  int id = Coord2Id(x, y);
 | 
			
		||||
  
 | 
			
		||||
  Node *check = NULL;
 | 
			
		||||
  
 | 
			
		||||
  if(check = CheckList(m_open, id)) {
 | 
			
		||||
    node->children[node->numChildren++] = check;
 | 
			
		||||
    
 | 
			
		||||
    // We have found an awesome route, update the node and variables.
 | 
			
		||||
    if(g < check->g) {
 | 
			
		||||
      check->parent = node;
 | 
			
		||||
      check->g 	    = g;
 | 
			
		||||
      check->f	    = g+check->h;
 | 
			
		||||
      //Func(udNotifyChild, node, check, NC_OPENADD_UP, NCData);
 | 
			
		||||
    } else {
 | 
			
		||||
      //Func(udNotifyChild, node, check, 2, NCData);
 | 
			
		||||
    }
 | 
			
		||||
  } else if(check = CheckList(m_closed, id)) {
 | 
			
		||||
    node->children[node->numChildren++] = check;
 | 
			
		||||
      
 | 
			
		||||
    if(g < check->g) {
 | 
			
		||||
    check->parent = node;
 | 
			
		||||
    check->g      = g;
 | 
			
		||||
    check->f      = g+check->h;
 | 
			
		||||
    //Func(udNotifyChild, node, check, 3, NCData);
 | 
			
		||||
 | 
			
		||||
    // Update the parents.
 | 
			
		||||
    UpdateParents(check);
 | 
			
		||||
    } else {
 | 
			
		||||
      //Func(udNotifyChild, node, check, 4, NCData);
 | 
			
		||||
    }
 | 
			
		||||
  } else {
 | 
			
		||||
    Node *newnode = new Node(x, y);
 | 
			
		||||
    newnode->parent = node;
 | 
			
		||||
    newnode->g  = g;
 | 
			
		||||
    newnode->h  = abs(x - m_destx) + abs(y - m_desty);
 | 
			
		||||
    newnode->f  = newnode->g + newnode->h;
 | 
			
		||||
    newnode->id = Coord2Id(x, y);
 | 
			
		||||
        
 | 
			
		||||
    AddToOpen(newnode);
 | 
			
		||||
    node->children[node->numChildren++] = newnode;
 | 
			
		||||
    
 | 
			
		||||
    //Func(udNotifyChild, node, newnode, 5, NCData);
 | 
			
		||||
  }
 | 
			
		||||
}  
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
void AStar::UpdateParent(Node *node) {
 | 
			
		||||
  int g = node->g;
 | 
			
		||||
  int c = node->numChildren;
 | 
			
		||||
  
 | 
			
		||||
  Node *child = NULL;
 | 
			
		||||
  for(int i = 0; i < c; i++) {
 | 
			
		||||
    child = node->children[i];
 | 
			
		||||
    if(g + 1 < child->g) {
 | 
			
		||||
      child->g = g + 1;
 | 
			
		||||
      child->f = child->g + child->h;
 | 
			
		||||
      child->parent = node;
 | 
			
		||||
      Push(child);
 | 
			
		||||
    } 
 | 
			
		||||
  }
 | 
			
		||||
  Node *parent;
 | 
			
		||||
  
 | 
			
		||||
  while(m_stack) {
 | 
			
		||||
    parent = Pop();
 | 
			
		||||
    c = parent->numC22hildren;
 | 
			
		||||
    for(int i = 0; i < c; i++) {
 | 
			
		||||
      child = parent->children[i];
 | 
			
		||||
 | 
			
		||||
      if(parent->g + 1 < child->g) {
 | 
			
		||||
        child->g = parent->g + Func(udCost, parent, child, NC_INITIALADD, CBData);
 | 
			
		||||
        child->f = child->g + child->h;
 | 
			
		||||
        child->parent = parent;
 | 
			
		||||
        Push(child);
 | 
			
		||||
      }
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void AStar::Push(Node *node) {
 | 
			
		||||
  if(!m_stack) {
 | 
			
		||||
     m_stack = new Stack;
 | 
			
		||||
     m_stack->data = node;
 | 
			
		||||
     m_stack->next = NULL;
 | 
			
		||||
  } else {
 | 
			
		||||
    Stack *temp = new Stack;
 | 
			
		||||
    temp->data  = node;
 | 
			
		||||
    temp->next  = m_stack;
 | 
			
		||||
    m_stack = temp;
 | 
			
		||||
  }    
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
Node AStar::*Pop(void) {
 | 
			
		||||
  Node *data  = m_stack->data;
 | 
			
		||||
  Stack *temp = m_stack;
 | 
			
		||||
 | 
			
		||||
  m_stack = temp->next;
 | 
			
		||||
  delete temp;
 | 
			
		||||
 | 
			
		||||
  return data;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
Node AStar::*CheckList(Node *node, int id) {
 | 
			
		||||
  while(node) {
 | 
			
		||||
    if(node->id == id)  return node; 
 | 
			
		||||
    
 | 
			
		||||
    node = node->next;
 | 
			
		||||
  }
 | 
			
		||||
  return NULL;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// Get the best node in the open list to enable us to find
 | 
			
		||||
// the best route to take.
 | 
			
		||||
Node AStar::*GetBest(void) {
 | 
			
		||||
  if(!m_open) { return NULL; }
 | 
			
		||||
  
 | 
			
		||||
  Node *temp  = m_open;
 | 
			
		||||
  Node *temp2 = m_closed;
 | 
			
		||||
  m_open = temp->next;
 | 
			
		||||
 | 
			
		||||
  //Func(udNotifyList, NULL, temp, NL_DELETEOPEN, NCData);                           
 | 
			
		||||
  m_closed = temp;
 | 
			
		||||
  m_closed->next = temp2;
 | 
			
		||||
  //Func(udNotifyList, NULL, m_closed, NL_ADDCLOSED, NCData);
 | 
			
		||||
 | 
			
		||||
  return temp;
 | 
			
		||||
}
 | 
			
		||||
@ -1,59 +0,0 @@
 | 
			
		||||
#ifndef _ASTAR_H_
 | 
			
		||||
#define _ASTAR_H_
 | 
			
		||||
#include "Node.h"
 | 
			
		||||
 | 
			
		||||
class AStar {
 | 
			
		||||
public:
 | 
			
		||||
  AStar(void);
 | 
			
		||||
  ~AStar(void);
 | 
			
		||||
 | 
			
		||||
  Func udCost;		// Called when the cost is needed.
 | 
			
		||||
  Func udValid;		// Check the validity of the coordanate.
 | 
			
		||||
  Func udNotifyChild;	// Child is called/checked (LinkChild).
 | 
			
		||||
  Func udNotifyList; 	// node is added to the open/closed list.
 | 
			
		||||
 | 
			
		||||
  void *CBData;		// Data passed back to the callback function.
 | 
			
		||||
  void *NCData; 	// Data paseed back to to notify child.
 | 
			
		||||
 | 
			
		||||
  bool GeneratePath(int startx, int starty, int destx, int desty);
 | 
			
		||||
  int Step(void);
 | 
			
		||||
  int InitStep(int startx, int starty, int destx, int desty);
 | 
			
		||||
  void SetRows(int r) { m_rows = r; }
 | 
			
		||||
  void Reset(void) { m_best = NULL; } 
 | 
			
		||||
  
 | 
			
		||||
  Node *GetBestNode(void) { return m_best; }
 | 
			
		||||
  
 | 
			
		||||
private:
 | 
			
		||||
  int m_rows; // Used to calculate unique ID for node->number.
 | 
			
		||||
  int m_startx;
 | 
			
		||||
  int m_starty;
 | 
			
		||||
  int m_destx;
 | 
			
		||||
  int m_desty;
 | 
			
		||||
 | 
			
		||||
  int m_ID;
 | 
			
		||||
  
 | 
			
		||||
 | 
			
		||||
  // Node list.
 | 
			
		||||
  Node *m_open;
 | 
			
		||||
  Node *m_closed;
 | 
			
		||||
  Node *m_best;
 | 
			
		||||
 | 
			
		||||
  Stack *m_stack;
 | 
			
		||||
 | 
			
		||||
  // Private methods.
 | 
			
		||||
  void AddToOpen(Node *node);
 | 
			
		||||
  void ClearNodes(void);
 | 
			
		||||
  void CreateChildren(Node *node);
 | 
			
		||||
  void LinkChild(Node *, Node *);
 | 
			
		||||
  void UpdateParent(Node *node);
 | 
			
		||||
 | 
			
		||||
  // Stack functions.
 | 
			
		||||
  void Push(Node *node);
 | 
			
		||||
  Node *Pop(void);
 | 
			
		||||
  Node *CheckList(Node *node, int number);
 | 
			
		||||
  Node *GetBest(void);
 | 
			
		||||
 | 
			
		||||
  inline int Coord2Id(int x, int y) { return x * m_rows + y; }  
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
#endif
 | 
			
		||||
@ -1,35 +0,0 @@
 | 
			
		||||
#include "Entity.h"
 | 
			
		||||
 | 
			
		||||
Entity::Entity(GameWorld* const gameWorld) :
 | 
			
		||||
    m_canBeRemoved(false),
 | 
			
		||||
    m_world(gameWorld) {}
 | 
			
		||||
 | 
			
		||||
Entity::~Entity(void) {}
 | 
			
		||||
 | 
			
		||||
bool Entity::CanBeRemoved(void) const {
 | 
			
		||||
  return m_canBeRemoved;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void Entity::Destroy(void) {
 | 
			
		||||
  m_canBeRemoved = true;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void Entity::Prepare(float dt) {
 | 
			
		||||
  OnPrepare(dt);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void Entity::Render(void) const {
 | 
			
		||||
  OnRender();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void Entity::OnPostRender(void) {
 | 
			
		||||
  OnPostRender();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
bool Entity::Initialize(void) {
 | 
			
		||||
  return OnInitiaize();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void Entity::Shutdown(void) {
 | 
			
		||||
  OnShutdown();
 | 
			
		||||
}
 | 
			
		||||
@ -1,46 +0,0 @@
 | 
			
		||||
#ifndef _ENTITY_H_
 | 
			
		||||
#define _ENTITY_H_
 | 
			
		||||
#include "Geometry.h"
 | 
			
		||||
#include "EntityType.h"
 | 
			
		||||
#include "Static.h"
 | 
			
		||||
 | 
			
		||||
class GameWorld;
 | 
			
		||||
 | 
			
		||||
/*
 | 
			
		||||
 * Entity is static because we will mainly be handling
 | 
			
		||||
 * pointers (that can be copied around) but we want
 | 
			
		||||
 * all entities to be initiaized by the gameworld.
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
class Entity : private Static {
 | 
			
		||||
public:
 | 
			
		||||
  Entity(GameWorld* const gameWorld);
 | 
			
		||||
  virtual ~Entity(void);
 | 
			
		||||
 | 
			
		||||
  void Prepare(float dt);
 | 
			
		||||
  void Render(void) const;
 | 
			
		||||
  void PostRender(void);
 | 
			
		||||
  bool Initialize(void);
 | 
			
		||||
  void Shutdown(void);
 | 
			
		||||
  bool CanBeRemoved(void) const;
 | 
			
		||||
  void Destroy(void);
 | 
			
		||||
 | 
			
		||||
  virtual Vector2 GetPosition(void) const = 0;
 | 
			
		||||
  //virtual Vector2 GetVelocity() const = 0;
 | 
			
		||||
  virtual void SetPosition(const Vector2& position) = 0;
 | 
			
		||||
 | 
			
		||||
  virtual EntityType GetType(void) const = 0;
 | 
			
		||||
 | 
			
		||||
private:
 | 
			
		||||
  virtual void OnPrepare(float dt)    = 0;
 | 
			
		||||
  virtual void OnRender(void) const   = 0;
 | 
			
		||||
  virtual void OnPostRender(void)     = 0;
 | 
			
		||||
  virtual bool OnInitiaize(void)      = 0;
 | 
			
		||||
  virtual void OnShutdown(void)       = 0;
 | 
			
		||||
 | 
			
		||||
  bool m_canBeRemoved;
 | 
			
		||||
 | 
			
		||||
  GameWorld* m_world;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
#endif
 | 
			
		||||
@ -1,8 +0,0 @@
 | 
			
		||||
#ifndef _ENTITYTYPES_H_
 | 
			
		||||
#define _ENTITYTYPES_H_
 | 
			
		||||
 | 
			
		||||
enum EntityType {
 | 
			
		||||
  PLAYER
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
#endif
 | 
			
		||||
							
								
								
									
										11
									
								
								src/libUnuk/Font.cpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										11
									
								
								src/libUnuk/Font.cpp
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,11 @@
 | 
			
		||||
#include "Font.h"
 | 
			
		||||
 | 
			
		||||
TTF_Font* Font(const char* filename, const int size) {
 | 
			
		||||
  ifstream font(filename);
 | 
			
		||||
 | 
			
		||||
  if(font.is_open() == false) {
 | 
			
		||||
    Debug::logger->message("Font: %s cannot be found.");
 | 
			
		||||
    exit(-1);
 | 
			
		||||
  }
 | 
			
		||||
  return TTF_OpenFont(filename, size);
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										11
									
								
								src/libUnuk/Font.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										11
									
								
								src/libUnuk/Font.h
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,11 @@
 | 
			
		||||
#ifndef _FONT_H_
 | 
			
		||||
#define _FONT_H_
 | 
			
		||||
#include <SDL/SDL_ttf.h>
 | 
			
		||||
#include <fstream>
 | 
			
		||||
#include <assert.h>
 | 
			
		||||
#include "Debug.h"
 | 
			
		||||
using namespace std;
 | 
			
		||||
 | 
			
		||||
TTF_Font* Font(const char*, const int);
 | 
			
		||||
 | 
			
		||||
#endif
 | 
			
		||||
@ -1,92 +0,0 @@
 | 
			
		||||
#ifndef _GEOMETRY_H_
 | 
			
		||||
#define _GEOMETRY_H_
 | 
			
		||||
#include <cmath>
 | 
			
		||||
 | 
			
		||||
struct TexCoord {
 | 
			
		||||
  float s, t;
 | 
			
		||||
  TexCoord(void):
 | 
			
		||||
    s(0.0f),
 | 
			
		||||
    t(0.0f) {}
 | 
			
		||||
 | 
			
		||||
  TexCoord(float s, float t):
 | 
			
		||||
    s(s),
 | 
			
		||||
    t(t) {}
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
struct Colour {
 | 
			
		||||
  float r, g, b, a;
 | 
			
		||||
  Colour(float R, float G, float B, float A):
 | 
			
		||||
    r(R),
 | 
			
		||||
    g(G),
 | 
			
		||||
    b(B),
 | 
			
		||||
    a(A) {}
 | 
			
		||||
 | 
			
		||||
  Colour(void):
 | 
			
		||||
    r(0.0f),
 | 
			
		||||
    g(0.0f),
 | 
			
		||||
    b(0.0f),
 | 
			
		||||
    a(0.0f) {}
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
struct Vector2 {
 | 
			
		||||
  float x, y;
 | 
			
		||||
  Vector2(float X, float Y):
 | 
			
		||||
    x(X),
 | 
			
		||||
    y(Y) {}
 | 
			
		||||
 | 
			
		||||
  Vector2(void):
 | 
			
		||||
    x(0.0f),
 | 
			
		||||
    y(0.0f) {}
 | 
			
		||||
 | 
			
		||||
  Vector2(const Vector2& v):
 | 
			
		||||
    x(v.x),
 | 
			
		||||
    y(v.y) {}
 | 
			
		||||
 | 
			
		||||
  Vector2 operator*(const float s) const {
 | 
			
		||||
    return Vector2(x*s, y*s);
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  Vector2& operator=(const Vector2& v) {
 | 
			
		||||
    if(this == &v) {
 | 
			
		||||
      return *this;
 | 
			
		||||
    }
 | 
			
		||||
    x = v.x;
 | 
			
		||||
    y = v.y;
 | 
			
		||||
 | 
			
		||||
    return *this;
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  Vector2& operator+=(const Vector2& v) {
 | 
			
		||||
    this->x += v.x;
 | 
			
		||||
    this->y += v.y;
 | 
			
		||||
 | 
			
		||||
    return *this;
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  const Vector2 operator-(const Vector2& v) const {
 | 
			
		||||
    Vector2 result;
 | 
			
		||||
    result.x = x - v.x;
 | 
			
		||||
    result.y = y - v.y;
 | 
			
		||||
 | 
			
		||||
    return result;
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  float length(void) const {
 | 
			
		||||
    return sqrtf(x*x+y*y);
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  void normalize(void) {
 | 
			
		||||
    float l = 1.0f / length();
 | 
			
		||||
    x *= l;
 | 
			
		||||
    y *= l;
 | 
			
		||||
  }
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
typedef Vector2 Vertex;
 | 
			
		||||
 | 
			
		||||
inline float degreesToRadians(const float degrees) {
 | 
			
		||||
  const float PIOver180 = 3.14159f / 180.0f;
 | 
			
		||||
  return degrees * PIOver180;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
#endif
 | 
			
		||||
@ -1,178 +0,0 @@
 | 
			
		||||
#include <cstdio>
 | 
			
		||||
#include <cstring>
 | 
			
		||||
#include <errno.h>
 | 
			
		||||
#include "ImageLoader.h"
 | 
			
		||||
#include "Debug.h"
 | 
			
		||||
#define BITMAP_TYPE 19778
 | 
			
		||||
 | 
			
		||||
// Initialize an empty image.
 | 
			
		||||
ImageLoader::ImageLoader(void) {
 | 
			
		||||
  Reset();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// Initializes an image with an image from the disk.
 | 
			
		||||
ImageLoader::ImageLoader(const char *filename) {
 | 
			
		||||
  Reset();
 | 
			
		||||
  LoadBMP(filename);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
ImageLoader::~ImageLoader(void) {
 | 
			
		||||
  if(colors != NULL) {
 | 
			
		||||
    delete [] colors;
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  if(pixelData != NULL) {
 | 
			
		||||
    delete [] pixelData;
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
bool ImageLoader::LoadBMP(const char* filename) {
 | 
			
		||||
  FILE *in	= NULL;
 | 
			
		||||
  bool result	= false;
 | 
			
		||||
 | 
			
		||||
  // Open the file for reading in binary mode.
 | 
			
		||||
  in = fopen(filename, "rb");
 | 
			
		||||
  if(in == NULL) {
 | 
			
		||||
    perror("Error");
 | 
			
		||||
    Debug::logger->message("\nError Number: %d", errno);
 | 
			
		||||
    return false;
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  fread(&bmfh, sizeof(BITMAPFILEHEADER), 1, in);
 | 
			
		||||
 | 
			
		||||
  // Check if this is even the right type of file.
 | 
			
		||||
  if(bmfh.bfType != BITMAP_TYPE) {
 | 
			
		||||
    perror("Error");
 | 
			
		||||
    Debug::logger->message("\nError Number: %d", errno);
 | 
			
		||||
    return false;
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  fread(&bmih, sizeof(BITMAPINFOHEADER), 1, in);
 | 
			
		||||
  width  = bmih.biWidth;
 | 
			
		||||
  height = bmih.biHeight;
 | 
			
		||||
  bpp    = bmih.biBitCount;
 | 
			
		||||
 | 
			
		||||
  // TODO: Get this running on 24-bit images too, right now it will seg fault if it is 24-bit.
 | 
			
		||||
  // Set the number of colors.
 | 
			
		||||
  LONG numColors = 1 << bmih.biBitCount;
 | 
			
		||||
 | 
			
		||||
  // The bitmap is not yet loaded.
 | 
			
		||||
  loaded = false;
 | 
			
		||||
  // Make sure memory is not lost.
 | 
			
		||||
  if(colors != NULL) {
 | 
			
		||||
    delete [] colors;
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  if(pixelData != NULL) {
 | 
			
		||||
    delete [] pixelData;
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  // Load the palette for 8 bits per pixel.
 | 
			
		||||
  if(bmih.biBitCount < 24) {
 | 
			
		||||
    colors = new RGBQUAD[numColors];
 | 
			
		||||
    fread(colors, sizeof(RGBQUAD), numColors, in);
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  DWORD size = bmfh.bfSize - bmfh.bfOffBits;
 | 
			
		||||
 | 
			
		||||
  BYTE *tempPixelData = NULL;
 | 
			
		||||
  tempPixelData = new BYTE[size];
 | 
			
		||||
 | 
			
		||||
  if(tempPixelData == NULL) {
 | 
			
		||||
    Debug::logger->message("\nError: Out of memory. Cannot find space to load image into memory.");
 | 
			
		||||
    fclose(in);
 | 
			
		||||
    return false;
 | 
			
		||||
  }
 | 
			
		||||
  
 | 
			
		||||
  fread(tempPixelData, sizeof(BYTE), size, in);
 | 
			
		||||
 | 
			
		||||
  result = FixPadding(tempPixelData, size);
 | 
			
		||||
  loaded = result;
 | 
			
		||||
 | 
			
		||||
  delete [] tempPixelData;
 | 
			
		||||
  fclose(in);
 | 
			
		||||
 | 
			
		||||
  return result;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
bool ImageLoader::FixPadding(BYTE const * const tempPixelData, DWORD size) {
 | 
			
		||||
  // byteWidth is the width of the actual image in bytes. padWidth is
 | 
			
		||||
  // the width of the image plus the extrapadding.
 | 
			
		||||
  LONG byteWidth, padWidth;
 | 
			
		||||
 | 
			
		||||
  // Set both to the width of the image.
 | 
			
		||||
  byteWidth = padWidth = (LONG)((float)width * (float)bpp / 8.0);
 | 
			
		||||
 | 
			
		||||
  // Add any extra space to bring each line to a DWORD boundary.
 | 
			
		||||
  short padding = padWidth % 4 != 0;
 | 
			
		||||
  padWidth += padding;
 | 
			
		||||
 | 
			
		||||
  DWORD diff;
 | 
			
		||||
  int offset;
 | 
			
		||||
 
 | 
			
		||||
  height = bmih.biHeight;
 | 
			
		||||
  // Set the diff to the actual image size (without any padding).
 | 
			
		||||
  diff = height * byteWidth;
 | 
			
		||||
  // allocate memory for the image.
 | 
			
		||||
  pixelData = new BYTE[diff];
 | 
			
		||||
  
 | 
			
		||||
  if(pixelData == NULL) {
 | 
			
		||||
    return false;
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  // ===================================================================
 | 
			
		||||
  // Bitmap is inverted, so the paddind needs to be removed and the
 | 
			
		||||
  // image reversed. Here you can start from the back of the file or
 | 
			
		||||
  // the front, after the header. The only problem is that some programs
 | 
			
		||||
  // will pad not only the data, but also the file size to be divisiaible
 | 
			
		||||
  // by 4 bytes.
 | 
			
		||||
  // ===================================================================
 | 
			
		||||
  if(height > 0) {
 | 
			
		||||
    offset = padWidth - byteWidth;
 | 
			
		||||
    for(unsigned int i = 0; i < size - 2; i += 4) {
 | 
			
		||||
      if((i + 1) % padWidth == 0) {
 | 
			
		||||
        i += offset;
 | 
			
		||||
      }
 | 
			
		||||
      // Now we need to swap the data for it to have the right order.
 | 
			
		||||
      *(pixelData + i)		= *(tempPixelData + i + 2); // R
 | 
			
		||||
      *(pixelData + i + 1)	= *(tempPixelData + i + 1); // G
 | 
			
		||||
      *(pixelData + i + 2)	= *(tempPixelData + i);	    // B
 | 
			
		||||
      *(pixelData + i + 3)	= *(tempPixelData + i + 3); // A
 | 
			
		||||
    }
 | 
			
		||||
  } else {
 | 
			
		||||
    // The image is not reserved. Only the padding needs to be removed.
 | 
			
		||||
    height = height * -1;
 | 
			
		||||
    offset = 0;
 | 
			
		||||
    while(offset < height) {
 | 
			
		||||
      memcpy((pixelData + (offset * byteWidth)), (tempPixelData + (offset * padWidth)), byteWidth);
 | 
			
		||||
      offset++;
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
  return true;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void ImageLoader::Reset(void) {
 | 
			
		||||
  width     = 0;
 | 
			
		||||
  height    = 0;
 | 
			
		||||
  pixelData = NULL;
 | 
			
		||||
  colors    = NULL;
 | 
			
		||||
  loaded    = false;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// Get the alpha channel as an array of bytes.
 | 
			
		||||
// The size of the array will return -1 on failure.
 | 
			
		||||
BYTE *ImageLoader::GetAlpha() const {
 | 
			
		||||
  LONG arraySize = width * height;
 | 
			
		||||
  BYTE *array = new BYTE[arraySize];
 | 
			
		||||
  
 | 
			
		||||
  if(array == NULL) {
 | 
			
		||||
    delete [] array;
 | 
			
		||||
    return NULL;
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  for(long i = 0; i < arraySize; i++) {
 | 
			
		||||
    // Jump to the alpha and extract it everytime.
 | 
			
		||||
    array[i] = pixelData[i * 4 + 3];
 | 
			
		||||
  }
 | 
			
		||||
  return array;
 | 
			
		||||
}
 | 
			
		||||
@ -1,76 +0,0 @@
 | 
			
		||||
// ===================================================================
 | 
			
		||||
// This image loader will read in a 32-bit bitmap.
 | 
			
		||||
// ===================================================================
 | 
			
		||||
 | 
			
		||||
#ifndef _IMAGELOADER_H_
 | 
			
		||||
#define _IMAGELOADER_H_
 | 
			
		||||
 | 
			
		||||
typedef unsigned char	BYTE;
 | 
			
		||||
typedef int		LONG;
 | 
			
		||||
typedef unsigned int	DWORD;
 | 
			
		||||
typedef unsigned short	WORD;
 | 
			
		||||
 | 
			
		||||
// Provides general information about the file.
 | 
			
		||||
typedef struct __attribute__ ((__packed__)) tagBITMAPFILEHEADER {
 | 
			
		||||
  WORD	bfType;
 | 
			
		||||
  DWORD	bfSize;
 | 
			
		||||
  WORD	bfReserved1;
 | 
			
		||||
  WORD	bfReserved2;
 | 
			
		||||
  DWORD	bfOffBits;
 | 
			
		||||
} BITMAPFILEHEADER, *PBITMAPFILEHEADER;
 | 
			
		||||
 | 
			
		||||
// The information header provides information specific to the image data.
 | 
			
		||||
typedef struct __attribute__ ((__packed__)) tagBITMAPINFOHEADER {
 | 
			
		||||
  DWORD	biSize;
 | 
			
		||||
  LONG  biWidth;
 | 
			
		||||
  LONG 	biHeight;
 | 
			
		||||
  WORD	biPlanes;
 | 
			
		||||
  WORD	biBitCount;
 | 
			
		||||
  DWORD biCompression;
 | 
			
		||||
  DWORD biSizeImage;
 | 
			
		||||
  DWORD biXPelsPerMeter;
 | 
			
		||||
  DWORD biYPelsPerMeter;
 | 
			
		||||
  DWORD biCLRUsed;
 | 
			
		||||
  DWORD biCLRImportant;
 | 
			
		||||
} BITMAPINFOHEADER, *PBITAPINFOHEADER;
 | 
			
		||||
 | 
			
		||||
// Color palette.
 | 
			
		||||
typedef struct __attribute__ ((__packed__)) tagRGBQUAD {
 | 
			
		||||
  BYTE rbgBlue;
 | 
			
		||||
  BYTE rgbGreen;
 | 
			
		||||
  BYTE rgbRed;
 | 
			
		||||
  BYTE rgbReserved;
 | 
			
		||||
} RGBQUAD;
 | 
			
		||||
 | 
			
		||||
class ImageLoader {
 | 
			
		||||
public:
 | 
			
		||||
  ImageLoader(void);
 | 
			
		||||
  ImageLoader(const char *filename);
 | 
			
		||||
 | 
			
		||||
  virtual ~ImageLoader(void);
 | 
			
		||||
  
 | 
			
		||||
  bool LoadBMP(const char *filename);
 | 
			
		||||
  BYTE *GetAlpha(void) const;
 | 
			
		||||
  
 | 
			
		||||
  LONG 	   GetHeight(void)  	const { return height;    }
 | 
			
		||||
  RGBQUAD  *GetColors(void) 	const { return colors;    }
 | 
			
		||||
  bool     GetLoaded(void)  	const { return loaded;    }
 | 
			
		||||
  BYTE 	   *GetPixelData(void)  const { return pixelData; }
 | 
			
		||||
  LONG	   GetWidth(void)	const { return width;     }
 | 
			
		||||
 | 
			
		||||
private:
 | 
			
		||||
  BITMAPFILEHEADER  bmfh;
 | 
			
		||||
  BITMAPINFOHEADER  bmih;
 | 
			
		||||
  RGBQUAD	    *colors;
 | 
			
		||||
  BYTE		    *pixelData;
 | 
			
		||||
  bool		    loaded;
 | 
			
		||||
  LONG		    width;
 | 
			
		||||
  LONG		    height;
 | 
			
		||||
  WORD		    bpp;
 | 
			
		||||
 | 
			
		||||
  // Private methods.
 | 
			
		||||
  void Reset(void);
 | 
			
		||||
  bool FixPadding(BYTE const * const tempPixelData, DWORD size);
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
#endif
 | 
			
		||||
@ -1,7 +1,7 @@
 | 
			
		||||
CC = g++
 | 
			
		||||
CFLAGS = -ansi -Wall -g
 | 
			
		||||
LDADD = -lGL -lGLU -lSDL
 | 
			
		||||
objects = Debug.o Entity.o ImageLoader.o Sprite.o Input.o \
 | 
			
		||||
objects = Debug.o Input.o \
 | 
			
		||||
 | 
			
		||||
.PHONY: default all clean
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@ -1,48 +0,0 @@
 | 
			
		||||
#ifndef _NODE_H_
 | 
			
		||||
#define _NODE_H_
 | 
			
		||||
#include <memory.h>
 | 
			
		||||
 | 
			
		||||
#ifndef NULL
 | 
			
		||||
#define NULL 0
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
#define NL_ADDOPEN	0
 | 
			
		||||
#define NL_STARTOPEN	1
 | 
			
		||||
#define	NL_DELETEOPEN	2
 | 
			
		||||
#define NL_ADDCLOSED	3
 | 
			
		||||
 | 
			
		||||
#define NC_INITIALADD	0
 | 
			
		||||
#define NC_OPENADD_UP	1
 | 
			
		||||
#define NC_OPENADD	2
 | 
			
		||||
#define NC_CLOSEDADD_UP 3
 | 
			
		||||
#define NC_CLOSEADD 	4
 | 
			
		||||
#define NC_NEWADD	5
 | 
			
		||||
 | 
			
		||||
class Node {
 | 
			
		||||
public:
 | 
			
		||||
  Node(int posx = -1, int posy = -1) : x(posx), y(posy), id(0), numChildren(0) {
 | 
			
		||||
    parent = next = NULL;
 | 
			
		||||
    memset(children, 0, sizeof(children));
 | 
			
		||||
  }
 | 
			
		||||
  
 | 
			
		||||
  // Fitness, goal, heuristic.
 | 
			
		||||
  int f, g, h; 
 | 
			
		||||
  // Position x and y.
 | 
			
		||||
  int x, y;
 | 
			
		||||
  int numChildren; // x*m_rows+y
 | 
			
		||||
  int id;
 | 
			
		||||
 | 
			
		||||
  Node *parent;
 | 
			
		||||
  Node *next;
 | 
			
		||||
  // Square tiles.
 | 
			
		||||
  Node *children[8];
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
struct Stack {
 | 
			
		||||
  Node  *data;
 | 
			
		||||
  Stack *next;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
typedef int(*Func) (Node *, 	 Node *, int, void *); 
 | 
			
		||||
                            	
 | 
			
		||||
#endif
 | 
			
		||||
							
								
								
									
										8
									
								
								src/libUnuk/Rect.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										8
									
								
								src/libUnuk/Rect.h
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,8 @@
 | 
			
		||||
#ifndef _RECT_H_
 | 
			
		||||
#define _RECT_H_
 | 
			
		||||
#include <SDL/SDL.h>
 | 
			
		||||
#include <iostream> // May not need this.
 | 
			
		||||
using namespace std;
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
#endif
 | 
			
		||||
@ -1,249 +0,0 @@
 | 
			
		||||
#include <GL/glut.h>
 | 
			
		||||
#include <iostream>
 | 
			
		||||
#include <cstring>
 | 
			
		||||
#include "Sprite.h"
 | 
			
		||||
#include "ImageLoader.h"
 | 
			
		||||
#include "Debug.h"
 | 
			
		||||
 | 
			
		||||
Sprite::Sprite(string filename) {
 | 
			
		||||
  image = new ImageLoader(filename.c_str());
 | 
			
		||||
  angle = 0;
 | 
			
		||||
  x	= 0.0f;
 | 
			
		||||
  y	= 0.0f;
 | 
			
		||||
  SetPivot(0.0f, 0.0f);
 | 
			
		||||
  SetScale(1.0f, 1.0f);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
Sprite::~Sprite(void) {
 | 
			
		||||
  delete image;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// Enable 2D drawing mode to draw our sprites. This function MUST be
 | 
			
		||||
// called before any sprite is drawn on screen using the Draw method.
 | 
			
		||||
void Sprite::Enable2D(void) {
 | 
			
		||||
  GLint iViewport[4];
 | 
			
		||||
  
 | 
			
		||||
  // Get a copy of the viewport.
 | 
			
		||||
  glGetIntegerv(GL_VIEWPORT, iViewport);
 | 
			
		||||
  glPushMatrix();
 | 
			
		||||
  glLoadIdentity();
 | 
			
		||||
 | 
			
		||||
  // Save a copy of the projection atrix so that we can restore
 | 
			
		||||
  // it when it's time to do 3D rendering again.
 | 
			
		||||
  glMatrixMode(GL_PROJECTION);
 | 
			
		||||
  glPushMatrix();
 | 
			
		||||
  glLoadIdentity();
 | 
			
		||||
 | 
			
		||||
  // Set upt the orthographic projection.
 | 
			
		||||
  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);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// Disables the 2D drawing. This can be called before you are done 
 | 
			
		||||
// drawing all 2D sprites on screen using the Draw method.
 | 
			
		||||
void Sprite::Disable2D(void) {
 | 
			
		||||
  glPopAttrib();
 | 
			
		||||
  glMatrixMode(GL_PROJECTION);
 | 
			
		||||
  glPopMatrix();
 | 
			
		||||
  glMatrixMode(GL_MODELVIEW);
 | 
			
		||||
  glPopMatrix();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// Initializes extensions, textures, render states, etc. before rendering.
 | 
			
		||||
void Sprite::InitScene(void) {
 | 
			
		||||
  // Disable lighting.
 | 
			
		||||
  glDisable(GL_LIGHTING);
 | 
			
		||||
  // Disable dithering.
 | 
			
		||||
  glDisable(GL_DITHER);
 | 
			
		||||
  // Disable blending (for now).
 | 
			
		||||
  glDisable(GL_BLEND);
 | 
			
		||||
  // Disable depth testing.
 | 
			
		||||
  glDisable(GL_DEPTH_TEST);
 | 
			
		||||
 | 
			
		||||
  // Is the extension supported on this driver/card?
 | 
			
		||||
  if(!IsExtensionSupported("GL_ARB_texture_rectangle")) {
 | 
			
		||||
    Debug::logger->message("\nERROR: Texture rectangles not supported on this video card!");
 | 
			
		||||
    exit(-1);
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  // TODO:
 | 
			
		||||
  // If your machine does not support GL_NV_texture_rectangle, you can try
 | 
			
		||||
  // using GL_EXT_texture_rectangle. Maybe I will run a test so I can support both.
 | 
			
		||||
 | 
			
		||||
  // Enable the texture rectangle extension.
 | 
			
		||||
  glEnable(GL_TEXTURE_RECTANGLE_ARB);
 | 
			
		||||
 | 
			
		||||
  // Generate one texture ID.
 | 
			
		||||
  glGenTextures(1, &textureID);
 | 
			
		||||
  // Bind the texture using GL_TEXTURE_RECTANGLE_NV
 | 
			
		||||
  glBindTexture(GL_TEXTURE_RECTANGLE_ARB, textureID);
 | 
			
		||||
  // Enable bilinear filtering on this texture.
 | 
			
		||||
  glTexParameteri(GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
 | 
			
		||||
  glTexParameteri(GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
 | 
			
		||||
 | 
			
		||||
  // Write the 32-bit RGBA texture buffer to video memory.
 | 
			
		||||
  glTexImage2D(GL_TEXTURE_RECTANGLE_ARB, 0, GL_RGBA, image->GetWidth(), image->GetHeight(),
 | 
			
		||||
		0, GL_RGBA, GL_UNSIGNED_BYTE, image->GetPixelData());
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// =================================================================
 | 
			
		||||
// Set the pivot point in relation to the sprite itself, that is
 | 
			
		||||
// using the object coordinates system. In this coordinate system
 | 
			
		||||
// the bottom left point of the object is at (0,0) and the top
 | 
			
		||||
// right is at (1,1).
 | 
			
		||||
//
 | 
			
		||||
// Example: To set the pivot to be in the middle of the sprite use
 | 
			
		||||
// (0.5, 0.5) default values are (1,1).
 | 
			
		||||
// pivotX can be any value, but when x is in the range [0,1] the
 | 
			
		||||
// pivot is inside the sprite where 0 is the left edge of the sprite
 | 
			
		||||
// and 1 is the right edge of the sprite.
 | 
			
		||||
// pivotY is the same as pivotX but when y is in the range of [0,1]
 | 
			
		||||
// the pivot is inside the sprite where 0 is the bottom edge of the
 | 
			
		||||
// sprite and 1 is the top edge of the sprite.
 | 
			
		||||
// =================================================================
 | 
			
		||||
void Sprite::SetPivot(GLfloat pivotX, GLfloat pivotY) {
 | 
			
		||||
  GLfloat deltaPivotX = pivotX - GetPivotX();
 | 
			
		||||
  GLfloat deltaPivotY = pivotY - GetPivotY();
 | 
			
		||||
 | 
			
		||||
  this->pivotX = pivotX;
 | 
			
		||||
  this->pivotY = pivotY;
 | 
			
		||||
 | 
			
		||||
  x += deltaPivotX * image->GetWidth();
 | 
			
		||||
  y += deltaPivotY * image->GetHeight();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// =================================================================
 | 
			
		||||
// Sets the pivot to be at the point where object's pivot is set.
 | 
			
		||||
// obj is the reference object to whose pivot we will set this pivot
 | 
			
		||||
// to be.
 | 
			
		||||
// Note: If the obj pivot changes or the obj moves after the SetPivot
 | 
			
		||||
// call has been issued, the pivot of this object will not reflect these
 | 
			
		||||
// changes. You must call SetPivot again with that object to update the
 | 
			
		||||
// pivot information.
 | 
			
		||||
// =================================================================
 | 
			
		||||
void Sprite::SetPivot(const Sprite &obj) {
 | 
			
		||||
  // This x location if the pivot was at SetPivot(0, 0);
 | 
			
		||||
  GLint worldX;
 | 
			
		||||
  // This y location it the pivot was at SetPivot(0, 0);
 | 
			
		||||
  GLint worldY;
 | 
			
		||||
  GLfloat newPivotX;
 | 
			
		||||
  GLfloat newPivotY;
 | 
			
		||||
 
 | 
			
		||||
  worldX = x - GetPivotX() * image->GetWidth();
 | 
			
		||||
  worldY = y - GetPivotY() * image->GetHeight();
 | 
			
		||||
 | 
			
		||||
  newPivotX = (float)(obj.x - worldX) / image->GetWidth();
 | 
			
		||||
  newPivotY = (float)(obj.y - worldY) / image->GetHeight();
 | 
			
		||||
 | 
			
		||||
  SetPivot(newPivotX, newPivotY);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// Help determine if an OpenGL extension is supported on the target machine
 | 
			
		||||
// at runtime.
 | 
			
		||||
bool Sprite::IsExtensionSupported(const char *extension) const {
 | 
			
		||||
  const GLubyte *extensions = NULL;
 | 
			
		||||
  const GLubyte *start;
 | 
			
		||||
  GLubyte *where, *terminator;
 | 
			
		||||
 | 
			
		||||
  // Extension names should not have spaces.
 | 
			
		||||
  where = (GLubyte *) strchr(extension, ' ');
 | 
			
		||||
 | 
			
		||||
  if (where || *extension == '\0')  {
 | 
			
		||||
    return false;
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  extensions = glGetString(GL_EXTENSIONS);
 | 
			
		||||
 | 
			
		||||
  // It takes a bit of care to be fool-proof about parsing the
 | 
			
		||||
  // OpenGL extensions string. Don't be fooled by sub-strings, etc.
 | 
			
		||||
  start = extensions;
 | 
			
		||||
 | 
			
		||||
  for (;;)  {
 | 
			
		||||
    where = (GLubyte *) strstr((const char *) start, extension);
 | 
			
		||||
 | 
			
		||||
    if (!where) {
 | 
			
		||||
       break;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    terminator = where + strlen(extension);
 | 
			
		||||
    if (where == start || *(where - 1) == ' ') {
 | 
			
		||||
      if (*terminator == ' ' || *terminator == '\0') {
 | 
			
		||||
        return true;
 | 
			
		||||
      }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    start = terminator;
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  return false;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void Sprite::Render(void) {
 | 
			
		||||
  InitScene();
 | 
			
		||||
 | 
			
		||||
  glEnable(GL_BLEND);
 | 
			
		||||
  glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
 | 
			
		||||
  glEnable(GL_TEXTURE_2D);
 | 
			
		||||
 | 
			
		||||
  // Set the primitive color to white
 | 
			
		||||
  glColor3f(1.0f, 1.0f, 1.0f);
 | 
			
		||||
  // Bind the texture to the polygons
 | 
			
		||||
  glBindTexture(GL_TEXTURE_RECTANGLE_ARB, textureID);
 | 
			
		||||
 | 
			
		||||
  glPushMatrix();
 | 
			
		||||
 | 
			
		||||
  GLfloat transX = 1;
 | 
			
		||||
  GLfloat transY = 1;
 | 
			
		||||
 | 
			
		||||
  if(x != 0.0) {
 | 
			
		||||
    transX = x;
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  if(y != 0.0) {
 | 
			
		||||
    transY = y;
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  glLoadIdentity();
 | 
			
		||||
  glTranslatef(transX, transY, 0);
 | 
			
		||||
  glScalef(scaleX, scaleY, 1.0);
 | 
			
		||||
  glRotatef(angle, 0.0, 0.0, 1.0);
 | 
			
		||||
 | 
			
		||||
  // =================================================================
 | 
			
		||||
  // Render a quad
 | 
			
		||||
  // Instead of the using (s,t) coordinates, with the GL_NV_texture_rectangle
 | 
			
		||||
  // extension, you need to use the actual dimensions of the texture.
 | 
			
		||||
  // This makes using 2D sprites for games and emulators much easier now
 | 
			
		||||
  // that you won't have to convert :)
 | 
			
		||||
  //
 | 
			
		||||
  // convert the coordinates so that the bottom left corner changes to
 | 
			
		||||
  // (0, 0) -> (1, 1) and the top right corner changes from (1, 1) -> (0, 0)
 | 
			
		||||
  // we will use this new coordinate system to calculate the location of the sprite
 | 
			
		||||
  // in the world coordinates to do the rotation and scaling. This mapping is done in
 | 
			
		||||
  // order to make implementation simpler in this class and let the caller keep using
 | 
			
		||||
  // the standard OpenGL coordinates system (bottom left corner at (0, 0))
 | 
			
		||||
  // =================================================================
 | 
			
		||||
  glBegin(GL_QUADS);
 | 
			
		||||
    glTexCoord2i(0, 0);
 | 
			
		||||
    glVertex2i(-pivotX * image->GetWidth(), -pivotY * image->GetHeight());
 | 
			
		||||
    
 | 
			
		||||
    glTexCoord2i(0, image->GetHeight());
 | 
			
		||||
    glVertex2i(-pivotX * image->GetWidth(), (1 - pivotY) * image->GetHeight());
 | 
			
		||||
 | 
			
		||||
    glTexCoord2i(image->GetWidth(), image->GetHeight());
 | 
			
		||||
    glVertex2i( (1 - pivotX) * image->GetWidth(), (1 - pivotY) * image->GetHeight());
 | 
			
		||||
 | 
			
		||||
    glTexCoord2i(image->GetWidth(), 0);
 | 
			
		||||
    glVertex2i( (1 - pivotX) * image->GetWidth(), -pivotY * image->GetHeight());
 | 
			
		||||
  glEnd();
 | 
			
		||||
 | 
			
		||||
  glPopMatrix();
 | 
			
		||||
}
 | 
			
		||||
@ -1,64 +0,0 @@
 | 
			
		||||
#ifndef _SPRITE_H_
 | 
			
		||||
#define _SPRITE_H_
 | 
			
		||||
#include <GL/glut.h>
 | 
			
		||||
#include <string>
 | 
			
		||||
#include "ImageLoader.h"
 | 
			
		||||
 | 
			
		||||
using namespace std;
 | 
			
		||||
 | 
			
		||||
class ImageLoader;
 | 
			
		||||
 | 
			
		||||
class Sprite {
 | 
			
		||||
public:
 | 
			
		||||
  static void Enable2D(void);
 | 
			
		||||
 
 | 
			
		||||
  static void Disable2D(void);
 | 
			
		||||
 | 
			
		||||
  Sprite(string filename);
 | 
			
		||||
  virtual ~Sprite(void);
 | 
			
		||||
 | 
			
		||||
  virtual void Render(void);
 | 
			
		||||
  virtual void Rotate(GLint degrees) { angle += degrees; }
 | 
			
		||||
  
 | 
			
		||||
  // Mutators.
 | 
			
		||||
  GLint GetAngle(void) const { return angle; }
 | 
			
		||||
  void SetAngle(GLint angle) { this->angle = angle; }
 | 
			
		||||
  void SetX(GLdouble x) { this->x = x; }
 | 
			
		||||
  void SetY(GLdouble y) { this->y = y; }
 | 
			
		||||
  GLint GetHeight(void) const { return image->GetHeight() * scaleY; }
 | 
			
		||||
  GLint GetWidth(void)  const { return image->GetWidth()  * scaleX; }
 | 
			
		||||
 | 
			
		||||
  void SetPivot(GLfloat pivotX, GLfloat pivotY);
 | 
			
		||||
  GLfloat GetPivotX(void) const { return pivotX; }
 | 
			
		||||
  GLfloat GetPivotY(void) const { return pivotY; }
 | 
			
		||||
 | 
			
		||||
  GLdouble GetX(void) const { return x; }
 | 
			
		||||
  GLdouble GetY(void) const { return y; }
 | 
			
		||||
 | 
			
		||||
  void SetPivot(const Sprite &obj);
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
  // =================================================================
 | 
			
		||||
  // Set the scale of the object. A scale of (1.0,1.0) means the sprite
 | 
			
		||||
  // maintains its original size. Values larger than 1 scales the sprite
 | 
			
		||||
  // up while values less than 1 shrink it down.
 | 
			
		||||
  // =================================================================
 | 
			
		||||
  void SetScale(GLfloat x, GLfloat y) { scaleX = x, scaleY = y; }
 | 
			
		||||
 | 
			
		||||
private:
 | 
			
		||||
  ImageLoader	*image;
 | 
			
		||||
  GLuint 	textureID;
 | 
			
		||||
  GLint		angle;
 | 
			
		||||
  GLdouble	x;
 | 
			
		||||
  GLdouble 	y;
 | 
			
		||||
  GLfloat	pivotX;
 | 
			
		||||
  GLfloat	pivotY;
 | 
			
		||||
  GLfloat	scaleX;
 | 
			
		||||
  GLfloat	scaleY;
 | 
			
		||||
 | 
			
		||||
  void InitScene(void);
 | 
			
		||||
 | 
			
		||||
  bool IsExtensionSupported(const char *extension) const;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
#endif
 | 
			
		||||
@ -1,22 +0,0 @@
 | 
			
		||||
#ifndef _STATIC_H_
 | 
			
		||||
#define _STATIC_H_
 | 
			
		||||
 | 
			
		||||
/*
 | 
			
		||||
 * Inheriting from this class will make the class uncopyable.
 | 
			
		||||
 * It is useful to do this because a lot of the time we won't
 | 
			
		||||
 * want to be able to copy stuff, like the window or the game class.
 | 
			
		||||
 *
 | 
			
		||||
 * I probably chose a bad name for this.
 | 
			
		||||
 *
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
class Static {
 | 
			
		||||
protected:
 | 
			
		||||
  Static() {}
 | 
			
		||||
  ~Static() {}
 | 
			
		||||
private:
 | 
			
		||||
  Static(const Static&);
 | 
			
		||||
  Static& operator=(const Static &);
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
#endif
 | 
			
		||||
							
								
								
									
										45
									
								
								src/libUnuk/Timer.cpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										45
									
								
								src/libUnuk/Timer.cpp
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,45 @@
 | 
			
		||||
#include "Timer.h"
 | 
			
		||||
 | 
			
		||||
Timer::Timer(void) {
 | 
			
		||||
  m_startTicks  = 0;
 | 
			
		||||
  m_pausedTicks = 0;
 | 
			
		||||
  m_paused = false;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
Timer::~Timer(void) {
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void Timer::Start(void) {
 | 
			
		||||
  m_paused = false;
 | 
			
		||||
  m_startTicks = SDL_GetTicks();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void Timer::Pause(void) {
 | 
			
		||||
  if(m_paused == false) {
 | 
			
		||||
    m_paused = true;
 | 
			
		||||
    m_pausedTicks = SDL_GetTicks() - m_startTicks;
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void Timer::Unpause(void) {
 | 
			
		||||
  if(m_paused == true) {
 | 
			
		||||
    m_paused = false;
 | 
			
		||||
    m_startTicks = SDL_GetTicks() - m_pausedTicks;
 | 
			
		||||
    m_pausedTicks = 0;
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
int Timer::GetTicks(void) {
 | 
			
		||||
  if(m_paused == true) {
 | 
			
		||||
    return m_pausedTicks;
 | 
			
		||||
  } else {
 | 
			
		||||
    return SDL_GetTicks() - m_startTicks;
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
string Timer::GetTicksStr(void) {
 | 
			
		||||
  stringstream str;
 | 
			
		||||
  str << GetTicks() << "ms";
 | 
			
		||||
 | 
			
		||||
  return str.str();
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										29
									
								
								src/libUnuk/Timer.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										29
									
								
								src/libUnuk/Timer.h
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,29 @@
 | 
			
		||||
#ifndef _TIMER_H_
 | 
			
		||||
#define _TIMER_H_
 | 
			
		||||
#include <SDL/SDL.h>
 | 
			
		||||
#include <string>
 | 
			
		||||
#include <sstream>
 | 
			
		||||
using namespace std;
 | 
			
		||||
 | 
			
		||||
class Timer {
 | 
			
		||||
public:
 | 
			
		||||
  Timer(void);
 | 
			
		||||
  ~Timer(void);
 | 
			
		||||
 | 
			
		||||
  void Pause(void);
 | 
			
		||||
  void Unpause(void);
 | 
			
		||||
  void Start(void);
 | 
			
		||||
 | 
			
		||||
  bool IsPaused(void) { return m_paused; }
 | 
			
		||||
 | 
			
		||||
  int GetTicks(void);
 | 
			
		||||
 | 
			
		||||
  string GetTicksStr(void);
 | 
			
		||||
 | 
			
		||||
private:
 | 
			
		||||
  bool m_paused;
 | 
			
		||||
  int  m_startTicks;
 | 
			
		||||
  int  m_pausedTicks;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
#endif
 | 
			
		||||
@ -1,250 +0,0 @@
 | 
			
		||||
#include <ctime>
 | 
			
		||||
#include <iostream>
 | 
			
		||||
#include <windows.h>
 | 
			
		||||
#include <GL/gl.h>
 | 
			
		||||
#include "../Libs/wglext.h"
 | 
			
		||||
#include "Win32Window.h"
 | 
			
		||||
#include "../Unuk/Game.h"
 | 
			
		||||
 | 
			
		||||
typedef HGLRC(APIENTRYP PFNWGLCREATECONTEXTATTRIBSARBPROC) (HDC, HGLRC, const int*);
 | 
			
		||||
PFNWGLCREATECONTEXTATTRIBSARBPROC wglCreateContextAttribsARB = NULL;
 | 
			
		||||
 | 
			
		||||
Win32Window::Win32Window(HINSTANCE hInstance) {
 | 
			
		||||
  m_isRunning = false;
 | 
			
		||||
  m_game      = NULL;
 | 
			
		||||
  m_hinstance = hInstance;
 | 
			
		||||
  m_lastTime  = 0;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
Win32Window::~Win32Window(void) {
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
bool Win32Window::Create(int width, int height, int bpp, bool fullscreen) {
 | 
			
		||||
  DWORD dwExStyle;
 | 
			
		||||
  DWORD dwStyle;
 | 
			
		||||
  
 | 
			
		||||
  m_isFullscreen = fullscreen;
 | 
			
		||||
 | 
			
		||||
  // Set up the window values.
 | 
			
		||||
  m_windowRect.left   = (long) 0;
 | 
			
		||||
  m_windowRect.right  = (long) width;
 | 
			
		||||
  m_windowRect.top    = (long) 0;
 | 
			
		||||
  m_windowRect.bottom = (long) height;
 | 
			
		||||
 | 
			
		||||
  // Set up the window class structure.
 | 
			
		||||
  m_windowClass.cbSize		= sizeof(WNDCLASSEX);
 | 
			
		||||
  m_windowClass.style		= CS_HREDRAW | CS_VREDRAW;
 | 
			
		||||
  m_windowClass.lpfnWndProc	= Win32Window::StaticWndProc; // Our static method is the event handler.
 | 
			
		||||
  m_windowClass.cbClsExtra	= 0;
 | 
			
		||||
  m_windowClass.cbWndExtra	= 0;
 | 
			
		||||
  m_windowClass.hInstance	= m_hinstance;
 | 
			
		||||
  m_windowClass.hIcon		= LoadIcon(NULL, IDI_APPLICATION);
 | 
			
		||||
  m_windowClass.hCurser		= LoadCursor(NULL, IDC_ARROW);
 | 
			
		||||
  m_windowClass.hbrBackground	= NULL;
 | 
			
		||||
  m_windowClass.lpszMenuName	= NULL;
 | 
			
		||||
  m_windowClass.lpszClassName	= "Unuk";
 | 
			
		||||
  m_windowClass.hIconSm		= LoadIcon(NULL, IDI_WINLOGO);
 | 
			
		||||
 | 
			
		||||
  // Register the window class.
 | 
			
		||||
  if(!RegisterClassEx(&m_windowClass)) {
 | 
			
		||||
    return false;
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  // We need to change the display mode if we are running fullscreen.
 | 
			
		||||
  if(m_isFullsceen) {
 | 
			
		||||
    // This is the device mode.
 | 
			
		||||
    DEVMODE dmScreenSettings;
 | 
			
		||||
    memset(&dmScreenSettings, 0, sizeof(smScreenSettings));
 | 
			
		||||
    dmScreenSettings.dmSize = sizeof(dmScreenSettings);
 | 
			
		||||
 | 
			
		||||
    // Set the screen width/height/bpp.
 | 
			
		||||
    dmScreenSettings.dmPelsWidth  = width;
 | 
			
		||||
    dmScreenSettings.dmPelsHeight = height;
 | 
			
		||||
    dmScreenSettings.dmBitsPerPel = bpp;
 | 
			
		||||
    dmScreenSettings.dwFields = DM_BITSPERPEL | DM_PELSWIDTH | DM_PELSHEIGHT;
 | 
			
		||||
 | 
			
		||||
    if(ChangeDisplaySettings(&dScreenSettings, CDS_FULLSCREEN) != DISP_CHANGE_SUCCESSFUL) {
 | 
			
		||||
      // Setting display mode failed, we will switch to windowed mode.
 | 
			
		||||
      MessageBox(NULL, "Display mode failed", NULL, MB_OK);
 | 
			
		||||
      m_isFullscreen = false;
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  // Check to see if we are still in fullscreen mode.
 | 
			
		||||
  if(m_fullscreen) {
 | 
			
		||||
    dwExStyle = WS_EX_APPWINDOW;
 | 
			
		||||
    dwStyle   = WS_POPUP;
 | 
			
		||||
    ShowCursor(false);
 | 
			
		||||
  } else {
 | 
			
		||||
    // fullscreen mode must have failed.
 | 
			
		||||
    dwExStyle = WS_EX_APPWINDOW | WS_EX_WINDOWEDGE;
 | 
			
		||||
    dwStyle   = WS_OVERLAPPEDWINDOW
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  // Adjusted the window to the requested size.
 | 
			
		||||
  AdjustWindowRectEx(&m_windowRect, swStyle, false, dwExStyle);
 | 
			
		||||
 | 
			
		||||
  // Now the class is regestered we can finaly create the window.
 | 
			
		||||
  m_hWnd = CreateWindowEx(NULL, "Unuk", dwStyle | WS_CLIPCHILDREN | WS_CLIPSIBLINGS, 0, 0,
 | 
			
		||||
			m_windowRect.right - m_windowRect.left, m_windowRect.bottom - m_windowRect.top,
 | 
			
		||||
			NULL, NULL, m_hinstance, this);
 | 
			
		||||
 | 
			
		||||
  // Let's make sure the window creation went as planned.
 | 
			
		||||
  if(!m_hWnd) return 0;
 | 
			
		||||
 | 
			
		||||
  m_hdc = GetDC(m_hWnd);
 | 
			
		||||
 | 
			
		||||
  // We know everything is ok, display and update the window now.
 | 
			
		||||
  ShowWindow(m_hWnd, SW_SHOW);
 | 
			
		||||
  UpdateWindow(m_hWnd);
 | 
			
		||||
 
 | 
			
		||||
  m_lastTime = GetTickCount() / 1000.0f;
 | 
			
		||||
  return true;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void Win32Window::Destroy(void) {
 | 
			
		||||
  // If we are in fullscreen we want to switch back to desktop, and show the mouse cursor.
 | 
			
		||||
  if(m_isFullscreen) {
 | 
			
		||||
    ChangeDisplaySettings(NULL, 0);
 | 
			
		||||
    ShowCursor(true);
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void Win32Window::AttachGame(Game* game) {
 | 
			
		||||
  m_game = game;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
bool Win32Window::IsRunning(void) {
 | 
			
		||||
  return m_isRunning;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void Win32Window::ProccessEvents(void) {
 | 
			
		||||
  MSG msg;
 | 
			
		||||
  
 | 
			
		||||
  // While there are messages in the queue, store them in msg.
 | 
			
		||||
  while(PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) {
 | 
			
		||||
    // Process the messages one at a time.
 | 
			
		||||
    TranslateMessage(&msg);
 | 
			
		||||
    DispatchMessage(&msg);
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void Win32Window::SetupPixelFormat(void) {
 | 
			
		||||
  int pixelFormat;
 | 
			
		||||
  
 | 
			
		||||
  PIXELFORMATDESCRIPTOR pfd = {
 | 
			
		||||
    sizeof(PIXELFORMATDESCRIPTOR),	// Size.
 | 
			
		||||
	1,				// Version.
 | 
			
		||||
	PFD_SUPPORT_OPENGL |		// OpenGL window.
 | 
			
		||||
	PFD_DRAW_TO_WINDOW |		// Render to window.
 | 
			
		||||
	PFD_DOUBLEBUFFER,		// Double buffer.
 | 
			
		||||
	PFD_TYPE_RGBA,			// Color type.
 | 
			
		||||
	32,				// Color Depth.
 | 
			
		||||
	0, 0, 0, 0, 0, 0,		// Color bits (ignored).
 | 
			
		||||
	0,				// No alpha buffer.
 | 
			
		||||
	0,				// Alpha bits (ignored).
 | 
			
		||||
	0,				// No accumulation buffer.
 | 
			
		||||
	0, 0, 0, 0,			// Accumulation bits (ignored).
 | 
			
		||||
	16,				// Depth buffer.
 | 
			
		||||
	0,				// No stencil buffer.
 | 
			
		||||
	0, 				// No auxiliary buffers.
 | 
			
		||||
	PFD_MAIN_PLANE,			// Main layer.
 | 
			
		||||
	0,				// Reserved.
 | 
			
		||||
	0, 0, 0,			// No layer, visible, damage masks.
 | 
			
		||||
  };
 | 
			
		||||
 | 
			
		||||
  pixelFormat = ChoosePixelFormat(m_hdc, &pfd);
 | 
			
		||||
  SetPixelFormat(m_hdc, pixelFormat, &pfd);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
LRESULT Win32Window::WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) {
 | 
			
		||||
  switch(uMsg) {
 | 
			
		||||
  // Create the window.
 | 
			
		||||
  case WM_CREATE:
 | 
			
		||||
    m_hdc = GetDC(hWnd);
 | 
			
		||||
    SetupPixelFormat();
 | 
			
		||||
 | 
			
		||||
    // Setup the OpenGL version. We want to use 3.0.
 | 
			
		||||
    int attribs[] = {
 | 
			
		||||
      WGL_CONTEXT_MAJOR_VERSION_ARB, 3,
 | 
			
		||||
      WGL_CONTEXT_MINOR_VERSION_ARB, 0,
 | 
			
		||||
      0
 | 
			
		||||
    };
 | 
			
		||||
 | 
			
		||||
    // Create a temporary context so we can get a pointer to the function.
 | 
			
		||||
    HGLRC tmpContext = wglCreateContext(m_hdc);
 | 
			
		||||
    // Make it the current.
 | 
			
		||||
    wglMakeCurrent(m_hdc, tmpContext);
 | 
			
		||||
    
 | 
			
		||||
    // Get the function pointer.
 | 
			
		||||
    wglCreateContextAttribsARB = (PFNWGLCCREATECONTEXTATTRIBSARBPROC) wglGetProcAddress("wglCreateContextAttribsARB");
 | 
			
		||||
 | 
			
		||||
    // If it is NULL, then GL 3.0 is not supported.
 | 
			
		||||
    if(!wglCreateContextAttribsARB) {
 | 
			
		||||
      Debug::logger->message("\nOpenGL 3.0 is not supported, falling back to GL 2.1");
 | 
			
		||||
      m_hglrc = tmpContext;
 | 
			
		||||
    } else {
 | 
			
		||||
      // Create an OpenGL 3.0 context using the new function.
 | 
			
		||||
      m_hglrc = wglCreateContextAttribsARB(m_hdc, 0, attribs);
 | 
			
		||||
      // Delete then temp context.
 | 
			
		||||
      wglDeleteContext(tmpContext);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    // Make the GL3 context current.
 | 
			
		||||
    wglMakeCurrent(m_hdc, m_hglrc);
 | 
			
		||||
    // Our window is now running.
 | 
			
		||||
    m_isRunning = true;
 | 
			
		||||
    break;
 | 
			
		||||
  case WM_DESTROY:
 | 
			
		||||
  case WM_CLOSE:
 | 
			
		||||
    wglMakeCurrent(m_hdc, NULL);
 | 
			
		||||
    wglDeleteContext(m_hglrc);
 | 
			
		||||
    m_isRunning = false;
 | 
			
		||||
    PostQuitMessage(0);
 | 
			
		||||
    return 0;
 | 
			
		||||
    break;
 | 
			
		||||
  case WM_SIZE:
 | 
			
		||||
    // Get the width and height.
 | 
			
		||||
    int height = HIWORD(lParam);
 | 
			
		||||
    int width  = LOWORD(lParam);
 | 
			
		||||
    getAttachedExample()->onResize(width, height);
 | 
			
		||||
    break;
 | 
			
		||||
  case WM_KEYDOWN:
 | 
			
		||||
    // If we detect the escape key, then please close the window.
 | 
			
		||||
    if(wParam == VK_ESCAPE) {
 | 
			
		||||
      DestroyWindow(m_hwnd);
 | 
			
		||||
    }
 | 
			
		||||
    break;
 | 
			
		||||
  default:
 | 
			
		||||
    break;
 | 
			
		||||
  }
 | 
			
		||||
  return DefWindowProc(hWnd, uMsg, wParam, lParam);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
LRESULT CALLBACK Win32Window::StaticWndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) {
 | 
			
		||||
  Win32Window* window = NULL;
 | 
			
		||||
 | 
			
		||||
  // If we see the create message.
 | 
			
		||||
  if(uMsg == WM_CREATE) {
 | 
			
		||||
    // Then get the pointer we stored during create.
 | 
			
		||||
    window = (Win32Window)(LPCREATESTRUCT)lParam)->lpCreateParams;
 | 
			
		||||
    // Associate the window pointer with the hWnd for the other events to access.
 | 
			
		||||
    SetWindowLongPtr(hWnd, GWL_USERDAA, (LONG_PTR)window);
 | 
			
		||||
  } else {
 | 
			
		||||
    // If this aint a creation event, then we should have stored a pointer to the window.
 | 
			
		||||
    window = (Win32Window)GetWindowLongPtr(hWnd, GWL_USERDATA);
 | 
			
		||||
    if(!window) {
 | 
			
		||||
      return DefWindowProc(hWnd, uMsg, wParam, lParam);
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
  // Call our window's member WndProc (allows us to access member variables).
 | 
			
		||||
  return window->WndProc(hWnd, uMsg, wParam, lParam)
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
float Win32Window::getElapsedSeconds() {
 | 
			
		||||
  float currentTime = float(GetTickCount()) / 1000.0f;
 | 
			
		||||
  float seconds	    = float(currentTime - m_lastTime);
 | 
			
		||||
  m_lastTime 	    = currentTime;
 | 
			
		||||
  return seconds;
 | 
			
		||||
}
 | 
			
		||||
@ -1,54 +0,0 @@
 | 
			
		||||
#ifndef _WIN32WINDOW_H_
 | 
			
		||||
#define _WIN32WINDOW_H_
 | 
			
		||||
#include <windows.h>
 | 
			
		||||
#include <ctime>
 | 
			
		||||
 | 
			
		||||
class Game; // Declaration of our Game class.
 | 
			
		||||
 | 
			
		||||
class Win32Window {
 | 
			
		||||
public:
 | 
			
		||||
  // Default constructor/deconstructor.
 | 
			
		||||
  Win32Window(HINSTANCE hInstance);
 | 
			
		||||
  ~Win32Window(void);
 | 
			
		||||
 | 
			
		||||
  bool Create(int width, int height, int bpp, bool fullscreen);
 | 
			
		||||
  void Destroy();
 | 
			
		||||
  void ProcessEvents();
 | 
			
		||||
  void AttachGame(Game* game);
 | 
			
		||||
 | 
			
		||||
  // Is the window running?
 | 
			
		||||
  bool IsRunning();
 | 
			
		||||
  
 | 
			
		||||
  void SwapBuffers() { SwapBuffers(m_hdc); }
 | 
			
		||||
 | 
			
		||||
  static LRESULT CALLBACK StaticWndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam);
 | 
			
		||||
  LRESULT CALLBACK WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam);
 | 
			
		||||
 | 
			
		||||
  float GetElapsedSeconds();
 | 
			
		||||
 | 
			
		||||
private:       
 | 
			
		||||
  // Pointer to the game class.
 | 
			
		||||
  Game* m_game;
 | 
			
		||||
  // Is the window still running?
 | 
			
		||||
  bool m_isRunning;
 | 
			
		||||
  bool m_fullscreen;
 | 
			
		||||
 | 
			
		||||
  // Window handle.
 | 
			
		||||
  HWND m_hWnd;
 | 
			
		||||
  // This is our rendering context.
 | 
			
		||||
  HGLRC m_hglrc;
 | 
			
		||||
  // The device context.
 | 
			
		||||
  HDC m_hdc;
 | 
			
		||||
  // Window bounds.
 | 
			
		||||
  RECT m_windowRect;
 | 
			
		||||
  // Application instance.
 | 
			
		||||
  HINSTANCE m_hinstance;
 | 
			
		||||
  WNDCLASSEX m_windowClass;
 | 
			
		||||
 | 
			
		||||
  void SetupPixelFormat(void);
 | 
			
		||||
  Game* GetAttachedGame() { return m_game; }
 | 
			
		||||
 | 
			
		||||
  float m_lastTime;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
#endif // _WIN32WINDOW_H_
 | 
			
		||||
		Loading…
	
		Reference in New Issue
	
	Block a user