├── .gitattributes ├── .gitignore ├── Build └── .keep ├── Content ├── AudioTest │ ├── City01.g2m │ ├── City01Hell.g2m │ ├── Coin.wav │ ├── Explosion.wav │ ├── Jump.wav │ ├── Laser.wav │ ├── LiberationSans-Regular.ttf │ ├── Powerup.wav │ ├── Readme.txt │ ├── ShortLoop.ogg │ ├── UFO.wav │ └── virt-robo.ogg ├── Flash │ ├── animations-monoclelogo.xml │ ├── animations-monocleman.xml │ ├── animations-test.xml │ ├── guy.png │ ├── monoclelogo │ │ ├── Hat.png │ │ ├── LeftStache.png │ │ ├── MainText.png │ │ ├── Monocle.png │ │ ├── RightStache.png │ │ └── SmallText.png │ ├── monocleman │ │ ├── eye_l.png │ │ ├── eye_r.png │ │ ├── eyebrow.png │ │ ├── hand_l.png │ │ ├── hand_r.png │ │ ├── hat.png │ │ ├── lowerarm_l.png │ │ ├── lowerarm_r.png │ │ ├── lowerleg_l.png │ │ ├── lowerleg_r.png │ │ ├── monocle.png │ │ ├── mustache.png │ │ ├── nose.png │ │ ├── torso.png │ │ ├── tortilla.png │ │ ├── upperarm_l.png │ │ ├── upperarm_r.png │ │ ├── upperleg_l.png │ │ └── upperleg_r.png │ ├── sheets-monoclelogo.xml │ └── sheets-monocleman.xml ├── Jumper │ └── Graphics │ │ └── Player.png ├── LevelEditorTest │ ├── graphics │ │ ├── bg-rock-0001.png │ │ ├── bg-rock-0002.png │ │ ├── fish-0001.png │ │ ├── player.png │ │ └── starfish-0001.png │ ├── level.xml │ └── project.xml ├── Ogmo │ ├── coin.png │ ├── level01.xml │ ├── player.png │ ├── project.xml │ ├── spike.png │ └── tiles.png ├── Pong │ ├── LiberationSans-Regular.ttf │ └── Readme.txt ├── PuppetTest │ ├── graphics │ │ ├── logo.png │ │ └── monocleman.png │ └── puppet.xml └── Scripted │ └── main.lua ├── Core ├── Asset.cpp ├── Asset.h ├── Assets.cpp ├── Assets.h ├── Audio │ ├── Audio.cpp │ ├── Audio.h │ ├── AudioAsset.cpp │ ├── AudioAsset.h │ ├── AudioAssetReader.cpp │ ├── AudioAssetReader.h │ ├── AudioCrypt.cpp │ ├── AudioCrypt.h │ ├── AudioDeck.cpp │ ├── AudioDeck.h │ ├── AudioDecoder.cpp │ ├── AudioDecoder.h │ ├── AudioVis.cpp │ ├── AudioVis.h │ ├── ChannelStream.cpp │ ├── ChannelStream.h │ ├── Decoders │ │ ├── OggDecoder.cpp │ │ ├── OggDecoder.h │ │ ├── WaveDecoder.cpp │ │ └── WaveDecoder.h │ ├── VisCache2.cpp │ ├── VisCache2.h │ ├── fft.cpp │ └── fft.h ├── CMakeLists.txt ├── Camera.cpp ├── Camera.h ├── Cocoa │ ├── CocoaEvents.h │ ├── CocoaEvents.mm │ ├── CocoaKeys.h │ ├── CocoaKeys.mm │ ├── CocoaOpenGL.h │ ├── CocoaOpenGL.mm │ ├── CocoaPlatform.h │ ├── CocoaPlatform.mm │ ├── CocoaWindowListener.h │ └── CocoaWindowListener.mm ├── Colliders │ ├── CircleCollider.cpp │ ├── CircleCollider.h │ ├── Collider.cpp │ ├── Collider.h │ ├── PathCollider.cpp │ ├── PathCollider.h │ ├── PolygonCollider.cpp │ ├── PolygonCollider.h │ ├── RectangleCollider.cpp │ └── RectangleCollider.h ├── Collision.cpp ├── Collision.h ├── CollisionData.cpp ├── CollisionData.h ├── Color.cpp ├── Color.h ├── ConfigValues.cpp ├── ConfigValues.h ├── Debug.cpp ├── Debug.h ├── Editor.cpp ├── Editor.h ├── Entity.cpp ├── Entity.h ├── FileNode.cpp ├── FileNode.h ├── FontAsset.h ├── GUI.cpp ├── GUI.h ├── Game.cpp ├── Game.h ├── Graphics.h ├── Graphics │ ├── Sprite.cpp │ ├── Sprite.h │ ├── SpriteAnimation.cpp │ ├── SpriteAnimation.h │ ├── Tilemap.cpp │ └── Tilemap.h ├── Input.cpp ├── Input.h ├── Level.cpp ├── Level.h ├── LevelEditor │ ├── FringeTile.cpp │ ├── FringeTile.h │ ├── ImageBrowser.cpp │ ├── ImageBrowser.h │ ├── LevelEditor.cpp │ ├── LevelEditor.h │ ├── Node.cpp │ ├── Node.h │ ├── PathMesh.cpp │ └── PathMesh.h ├── Linux │ ├── LinuxPlatform.cpp │ └── LinuxPlatform.h ├── Macros.h ├── Monocle.cpp ├── Monocle.h ├── MonocleToolkit.cpp ├── MonocleToolkit.h ├── OpenGL │ ├── OpenGLGraphics.cpp │ ├── OpenGLTTFFontAsset.cpp │ └── OpenGLTextureAsset.cpp ├── Platform.h ├── Puppet │ ├── Puppet.cpp │ ├── Puppet.h │ ├── PuppetEditor.cpp │ └── PuppetEditor.h ├── Random.cpp ├── Random.h ├── Rect.cpp ├── Rect.h ├── Scene.cpp ├── Scene.h ├── TTFFontAsset.h ├── TextureAsset.h ├── TextureAtlas.cpp ├── TextureAtlas.h ├── Tileset.cpp ├── Tileset.h ├── Transform.cpp ├── Transform.h ├── Tween.cpp ├── Tween.h ├── Vector2.cpp ├── Vector2.h ├── Vector3.cpp ├── Vector3.h ├── Windows │ ├── WindowsPlatform.cpp │ └── WindowsPlatform.h ├── XML │ ├── XMLFileNode.cpp │ └── XMLFileNode.h └── premake4-monocle.lua ├── Libraries ├── AL │ ├── EFX-Util.h │ ├── al.h │ ├── alc.h │ ├── efx-creative.h │ ├── efx.h │ └── xram.h ├── Compiled │ ├── MacOSX │ │ ├── adjust.sh │ │ ├── libGLEW.a │ │ ├── libogg.a │ │ ├── libvorbis.a │ │ ├── libvorbisenc.a │ │ └── libvorbisfile.a │ └── Win32 │ │ ├── EFX-Util_MT │ │ └── EFX-Util.lib │ │ ├── EFX-Util_MTDLL │ │ └── EFX-Util.lib │ │ ├── OpenAL32.lib │ │ ├── glew32s.lib │ │ ├── libogg_static.lib │ │ ├── libvorbis_static.lib │ │ └── libvorbisfile_static.lib ├── GL │ ├── glew.c │ ├── glew.h │ ├── glxew.h │ └── wglew.h ├── TinyXML │ ├── tinyxml.cpp │ ├── tinyxml.h │ ├── tinyxmlerror.cpp │ └── tinyxmlparser.cpp ├── ogg │ ├── ogg.h │ └── os_types.h ├── stb │ ├── stb_image.c │ ├── stb_image_write.h │ └── stb_truetype.h └── vorbis │ ├── codec.h │ ├── vorbisenc.h │ └── vorbisfile.h ├── Project └── Xcode4 │ └── MonocleTest │ ├── Monocle.xcodeproj │ ├── project.pbxproj │ ├── project.xcworkspace │ │ ├── contents.xcworkspacedata │ │ └── xcuserdata │ │ │ └── josh.xcuserdatad │ │ │ ├── WorkspaceSettings.xcsettings │ │ │ └── xcdebugger │ │ │ └── Expressions.xcexplist │ ├── xcshareddata │ │ └── xcschemes │ │ │ └── Monocle.xcscheme │ └── xcuserdata │ │ └── josh.xcuserdatad │ │ ├── xcdebugger │ │ └── Breakpoints.xcbkptlist │ │ └── xcschemes │ │ └── xcschememanagement.plist │ ├── Monocle │ ├── Monocle-Info.plist │ ├── Monocle-Prefix.pch │ └── en.lproj │ │ └── InfoPlist.strings │ └── MonocleTests │ ├── MonocleTests.xcodeproj │ ├── project.pbxproj │ ├── xcshareddata │ │ └── xcschemes │ │ │ └── Monocle Tests.xcscheme │ └── xcuserdata │ │ └── josh.xcuserdatad │ │ └── xcschemes │ │ └── xcschememanagement.plist │ └── MonocleTests │ ├── MonocleTests-Info.plist │ ├── MonocleTests-Prefix.pch │ └── en.lproj │ └── InfoPlist.strings ├── README ├── Samples ├── All │ └── premake4-All.lua ├── AudioTest │ ├── AudioTest.cpp │ ├── AudioTest.h │ ├── CMakeLists.txt │ └── Main.cpp ├── Flash │ ├── CMakeLists.txt │ ├── Flash.cpp │ ├── Flash.h │ └── Main.cpp ├── Jumper │ ├── CMakeLists.txt │ ├── Jumper.cpp │ ├── Jumper.h │ └── Main.cpp ├── LevelEditor │ ├── CMakeLists.txt │ ├── LevelEditorTest.cpp │ ├── LevelEditorTest.h │ └── Main.cpp ├── Ogmo │ ├── CMakeLists.txt │ ├── Main.cpp │ ├── Ogmo.cpp │ └── Ogmo.h ├── Pong │ ├── CMakeLists.txt │ ├── Main.cpp │ ├── Pong.cpp │ └── Pong.h ├── PuppetTest │ ├── CMakeLists.txt │ ├── Main.cpp │ ├── PuppetTest.cpp │ └── PuppetTest.h ├── RenderTests │ └── TextRenderTest.cpp ├── Scripted │ └── Main.cpp ├── TestSelector │ ├── Main.cpp │ └── premake4-TestSelector.lua └── premake4-test-generic.lua ├── Tests ├── InputHandlerTest │ ├── InputHandlerTest.h │ └── Main.cpp ├── Libraries │ └── cpptest │ │ ├── cpptest-assert.h │ │ ├── cpptest-collectoroutput.h │ │ ├── cpptest-compileroutput.h │ │ ├── cpptest-htmloutput.h │ │ ├── cpptest-output.h │ │ ├── cpptest-source.h │ │ ├── cpptest-suite.h │ │ ├── cpptest-textoutput.h │ │ ├── cpptest-time.h │ │ └── cpptest.h ├── Main.cpp ├── Tests.h └── Unit │ ├── AssetTest.cpp │ ├── AssetTest.h │ ├── AssetsTest.cpp │ ├── AssetsTest.h │ ├── CameraTest.cpp │ ├── CameraTest.h │ ├── FontAssetTest.cpp │ ├── FontAssetTest.h │ ├── VectorTest.cpp │ └── VectorTest.h ├── linux-build-basic.sh ├── premake4-helper.lua └── premake4.lua /.gitattributes: -------------------------------------------------------------------------------- 1 | *.sh eol=lf 2 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | Build 2 | CMakeCache.txt 3 | CMakeFiles 4 | Makefile 5 | *.cmake 6 | 7 | #Qt creator project files 8 | monocle.files 9 | monocle.includes 10 | monocle.config 11 | monocle.creator.* 12 | 13 | # OSX 14 | .DS_Store 15 | 16 | # Build artifacts 17 | *.obj 18 | 19 | # VS2010 20 | *.sdf 21 | *.opensdf 22 | *.suo 23 | *.tlog 24 | *.lastbuildstate 25 | *.unsuccessfulbuild 26 | *.manifest 27 | *.idb 28 | *.pdb 29 | *.ipch 30 | *.vcxproj.user 31 | [Dd]ebug 32 | [Rr]elease 33 | 34 | # XCode 35 | *.mode1 36 | *.mode1v3 37 | *.mode2v3 38 | *.perspective 39 | *.perspectivev3 40 | *.pbxuser 41 | *.xcuserstate 42 | -------------------------------------------------------------------------------- /Build/.keep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zaphire/Monocle-Engine/a4558b5436681ab0ec95aec388cbb791b26f0b81/Build/.keep -------------------------------------------------------------------------------- /Content/AudioTest/City01.g2m: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zaphire/Monocle-Engine/a4558b5436681ab0ec95aec388cbb791b26f0b81/Content/AudioTest/City01.g2m -------------------------------------------------------------------------------- /Content/AudioTest/City01Hell.g2m: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zaphire/Monocle-Engine/a4558b5436681ab0ec95aec388cbb791b26f0b81/Content/AudioTest/City01Hell.g2m -------------------------------------------------------------------------------- /Content/AudioTest/Coin.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zaphire/Monocle-Engine/a4558b5436681ab0ec95aec388cbb791b26f0b81/Content/AudioTest/Coin.wav -------------------------------------------------------------------------------- /Content/AudioTest/Explosion.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zaphire/Monocle-Engine/a4558b5436681ab0ec95aec388cbb791b26f0b81/Content/AudioTest/Explosion.wav -------------------------------------------------------------------------------- /Content/AudioTest/Jump.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zaphire/Monocle-Engine/a4558b5436681ab0ec95aec388cbb791b26f0b81/Content/AudioTest/Jump.wav -------------------------------------------------------------------------------- /Content/AudioTest/Laser.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zaphire/Monocle-Engine/a4558b5436681ab0ec95aec388cbb791b26f0b81/Content/AudioTest/Laser.wav -------------------------------------------------------------------------------- /Content/AudioTest/LiberationSans-Regular.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zaphire/Monocle-Engine/a4558b5436681ab0ec95aec388cbb791b26f0b81/Content/AudioTest/LiberationSans-Regular.ttf -------------------------------------------------------------------------------- /Content/AudioTest/Powerup.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zaphire/Monocle-Engine/a4558b5436681ab0ec95aec388cbb791b26f0b81/Content/AudioTest/Powerup.wav -------------------------------------------------------------------------------- /Content/AudioTest/Readme.txt: -------------------------------------------------------------------------------- 1 | Information on Liberation Fonts: 2 | http://en.wikipedia.org/wiki/Liberation_fonts -------------------------------------------------------------------------------- /Content/AudioTest/ShortLoop.ogg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zaphire/Monocle-Engine/a4558b5436681ab0ec95aec388cbb791b26f0b81/Content/AudioTest/ShortLoop.ogg -------------------------------------------------------------------------------- /Content/AudioTest/UFO.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zaphire/Monocle-Engine/a4558b5436681ab0ec95aec388cbb791b26f0b81/Content/AudioTest/UFO.wav -------------------------------------------------------------------------------- /Content/AudioTest/virt-robo.ogg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zaphire/Monocle-Engine/a4558b5436681ab0ec95aec388cbb791b26f0b81/Content/AudioTest/virt-robo.ogg -------------------------------------------------------------------------------- /Content/Flash/animations-test.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /Content/Flash/guy.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zaphire/Monocle-Engine/a4558b5436681ab0ec95aec388cbb791b26f0b81/Content/Flash/guy.png -------------------------------------------------------------------------------- /Content/Flash/monoclelogo/Hat.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zaphire/Monocle-Engine/a4558b5436681ab0ec95aec388cbb791b26f0b81/Content/Flash/monoclelogo/Hat.png -------------------------------------------------------------------------------- /Content/Flash/monoclelogo/LeftStache.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zaphire/Monocle-Engine/a4558b5436681ab0ec95aec388cbb791b26f0b81/Content/Flash/monoclelogo/LeftStache.png -------------------------------------------------------------------------------- /Content/Flash/monoclelogo/MainText.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zaphire/Monocle-Engine/a4558b5436681ab0ec95aec388cbb791b26f0b81/Content/Flash/monoclelogo/MainText.png -------------------------------------------------------------------------------- /Content/Flash/monoclelogo/Monocle.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zaphire/Monocle-Engine/a4558b5436681ab0ec95aec388cbb791b26f0b81/Content/Flash/monoclelogo/Monocle.png -------------------------------------------------------------------------------- /Content/Flash/monoclelogo/RightStache.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zaphire/Monocle-Engine/a4558b5436681ab0ec95aec388cbb791b26f0b81/Content/Flash/monoclelogo/RightStache.png -------------------------------------------------------------------------------- /Content/Flash/monoclelogo/SmallText.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zaphire/Monocle-Engine/a4558b5436681ab0ec95aec388cbb791b26f0b81/Content/Flash/monoclelogo/SmallText.png -------------------------------------------------------------------------------- /Content/Flash/monocleman/eye_l.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zaphire/Monocle-Engine/a4558b5436681ab0ec95aec388cbb791b26f0b81/Content/Flash/monocleman/eye_l.png -------------------------------------------------------------------------------- /Content/Flash/monocleman/eye_r.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zaphire/Monocle-Engine/a4558b5436681ab0ec95aec388cbb791b26f0b81/Content/Flash/monocleman/eye_r.png -------------------------------------------------------------------------------- /Content/Flash/monocleman/eyebrow.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zaphire/Monocle-Engine/a4558b5436681ab0ec95aec388cbb791b26f0b81/Content/Flash/monocleman/eyebrow.png -------------------------------------------------------------------------------- /Content/Flash/monocleman/hand_l.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zaphire/Monocle-Engine/a4558b5436681ab0ec95aec388cbb791b26f0b81/Content/Flash/monocleman/hand_l.png -------------------------------------------------------------------------------- /Content/Flash/monocleman/hand_r.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zaphire/Monocle-Engine/a4558b5436681ab0ec95aec388cbb791b26f0b81/Content/Flash/monocleman/hand_r.png -------------------------------------------------------------------------------- /Content/Flash/monocleman/hat.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zaphire/Monocle-Engine/a4558b5436681ab0ec95aec388cbb791b26f0b81/Content/Flash/monocleman/hat.png -------------------------------------------------------------------------------- /Content/Flash/monocleman/lowerarm_l.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zaphire/Monocle-Engine/a4558b5436681ab0ec95aec388cbb791b26f0b81/Content/Flash/monocleman/lowerarm_l.png -------------------------------------------------------------------------------- /Content/Flash/monocleman/lowerarm_r.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zaphire/Monocle-Engine/a4558b5436681ab0ec95aec388cbb791b26f0b81/Content/Flash/monocleman/lowerarm_r.png -------------------------------------------------------------------------------- /Content/Flash/monocleman/lowerleg_l.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zaphire/Monocle-Engine/a4558b5436681ab0ec95aec388cbb791b26f0b81/Content/Flash/monocleman/lowerleg_l.png -------------------------------------------------------------------------------- /Content/Flash/monocleman/lowerleg_r.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zaphire/Monocle-Engine/a4558b5436681ab0ec95aec388cbb791b26f0b81/Content/Flash/monocleman/lowerleg_r.png -------------------------------------------------------------------------------- /Content/Flash/monocleman/monocle.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zaphire/Monocle-Engine/a4558b5436681ab0ec95aec388cbb791b26f0b81/Content/Flash/monocleman/monocle.png -------------------------------------------------------------------------------- /Content/Flash/monocleman/mustache.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zaphire/Monocle-Engine/a4558b5436681ab0ec95aec388cbb791b26f0b81/Content/Flash/monocleman/mustache.png -------------------------------------------------------------------------------- /Content/Flash/monocleman/nose.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zaphire/Monocle-Engine/a4558b5436681ab0ec95aec388cbb791b26f0b81/Content/Flash/monocleman/nose.png -------------------------------------------------------------------------------- /Content/Flash/monocleman/torso.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zaphire/Monocle-Engine/a4558b5436681ab0ec95aec388cbb791b26f0b81/Content/Flash/monocleman/torso.png -------------------------------------------------------------------------------- /Content/Flash/monocleman/tortilla.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zaphire/Monocle-Engine/a4558b5436681ab0ec95aec388cbb791b26f0b81/Content/Flash/monocleman/tortilla.png -------------------------------------------------------------------------------- /Content/Flash/monocleman/upperarm_l.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zaphire/Monocle-Engine/a4558b5436681ab0ec95aec388cbb791b26f0b81/Content/Flash/monocleman/upperarm_l.png -------------------------------------------------------------------------------- /Content/Flash/monocleman/upperarm_r.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zaphire/Monocle-Engine/a4558b5436681ab0ec95aec388cbb791b26f0b81/Content/Flash/monocleman/upperarm_r.png -------------------------------------------------------------------------------- /Content/Flash/monocleman/upperleg_l.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zaphire/Monocle-Engine/a4558b5436681ab0ec95aec388cbb791b26f0b81/Content/Flash/monocleman/upperleg_l.png -------------------------------------------------------------------------------- /Content/Flash/monocleman/upperleg_r.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zaphire/Monocle-Engine/a4558b5436681ab0ec95aec388cbb791b26f0b81/Content/Flash/monocleman/upperleg_r.png -------------------------------------------------------------------------------- /Content/Flash/sheets-monoclelogo.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /Content/Flash/sheets-monocleman.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /Content/Jumper/Graphics/Player.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zaphire/Monocle-Engine/a4558b5436681ab0ec95aec388cbb791b26f0b81/Content/Jumper/Graphics/Player.png -------------------------------------------------------------------------------- /Content/LevelEditorTest/graphics/bg-rock-0001.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zaphire/Monocle-Engine/a4558b5436681ab0ec95aec388cbb791b26f0b81/Content/LevelEditorTest/graphics/bg-rock-0001.png -------------------------------------------------------------------------------- /Content/LevelEditorTest/graphics/bg-rock-0002.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zaphire/Monocle-Engine/a4558b5436681ab0ec95aec388cbb791b26f0b81/Content/LevelEditorTest/graphics/bg-rock-0002.png -------------------------------------------------------------------------------- /Content/LevelEditorTest/graphics/fish-0001.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zaphire/Monocle-Engine/a4558b5436681ab0ec95aec388cbb791b26f0b81/Content/LevelEditorTest/graphics/fish-0001.png -------------------------------------------------------------------------------- /Content/LevelEditorTest/graphics/player.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zaphire/Monocle-Engine/a4558b5436681ab0ec95aec388cbb791b26f0b81/Content/LevelEditorTest/graphics/player.png -------------------------------------------------------------------------------- /Content/LevelEditorTest/graphics/starfish-0001.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zaphire/Monocle-Engine/a4558b5436681ab0ec95aec388cbb791b26f0b81/Content/LevelEditorTest/graphics/starfish-0001.png -------------------------------------------------------------------------------- /Content/LevelEditorTest/level.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /Content/LevelEditorTest/project.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /Content/Ogmo/coin.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zaphire/Monocle-Engine/a4558b5436681ab0ec95aec388cbb791b26f0b81/Content/Ogmo/coin.png -------------------------------------------------------------------------------- /Content/Ogmo/player.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zaphire/Monocle-Engine/a4558b5436681ab0ec95aec388cbb791b26f0b81/Content/Ogmo/player.png -------------------------------------------------------------------------------- /Content/Ogmo/project.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /Content/Ogmo/spike.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zaphire/Monocle-Engine/a4558b5436681ab0ec95aec388cbb791b26f0b81/Content/Ogmo/spike.png -------------------------------------------------------------------------------- /Content/Ogmo/tiles.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zaphire/Monocle-Engine/a4558b5436681ab0ec95aec388cbb791b26f0b81/Content/Ogmo/tiles.png -------------------------------------------------------------------------------- /Content/Pong/LiberationSans-Regular.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zaphire/Monocle-Engine/a4558b5436681ab0ec95aec388cbb791b26f0b81/Content/Pong/LiberationSans-Regular.ttf -------------------------------------------------------------------------------- /Content/Pong/Readme.txt: -------------------------------------------------------------------------------- 1 | Information on Liberation Fonts: 2 | http://en.wikipedia.org/wiki/Liberation_fonts -------------------------------------------------------------------------------- /Content/PuppetTest/graphics/logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zaphire/Monocle-Engine/a4558b5436681ab0ec95aec388cbb791b26f0b81/Content/PuppetTest/graphics/logo.png -------------------------------------------------------------------------------- /Content/PuppetTest/graphics/monocleman.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zaphire/Monocle-Engine/a4558b5436681ab0ec95aec388cbb791b26f0b81/Content/PuppetTest/graphics/monocleman.png -------------------------------------------------------------------------------- /Content/PuppetTest/puppet.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | -------------------------------------------------------------------------------- /Content/Scripted/main.lua: -------------------------------------------------------------------------------- 1 | io.write "Something\n" 2 | 3 | Point = {} 4 | 5 | Point.new = function(x, y) 6 | local self = {} 7 | x = x or 0 8 | x = y or 0 9 | 10 | self.getx = function() return x end 11 | self.gety = function() return y end 12 | self.write = function() io.write(string.format("(%d, %d)\n", x, y)) end 13 | 14 | return self 15 | end 16 | 17 | p = Point.new(2,5) 18 | p.write() 19 | 20 | function HelloWorld() 21 | io.write "Hello, World!\n" 22 | local test = true 23 | if test == true then 24 | io.write "it's true!\n" 25 | end 26 | end 27 | -------------------------------------------------------------------------------- /Core/Asset.cpp: -------------------------------------------------------------------------------- 1 | #include "Asset.h" 2 | #include "Debug.h" 3 | #include "Assets.h" 4 | 5 | namespace Monocle 6 | { 7 | Asset::Asset(AssetType type) 8 | : type(type) 9 | { 10 | isCached = false; 11 | referenceCount = 0; 12 | } 13 | 14 | void Asset::AddReference() 15 | { 16 | referenceCount++; 17 | 18 | //Debug::Log("referenceCount increased for: " + filename); 19 | //Debug::Log(referenceCount); 20 | } 21 | 22 | void Asset::RemoveReference() 23 | { 24 | referenceCount--; 25 | 26 | Debug::Log("referenceCount decreased for: " + filename); 27 | Debug::Log(referenceCount); 28 | 29 | if (referenceCount == 0) 30 | { 31 | if (!isCached) 32 | { 33 | Unload(); 34 | Assets::RemoveAsset(this); 35 | } 36 | } 37 | } 38 | 39 | std::string Asset::GetName() 40 | { 41 | //Will this stop working correctly if the content path is changed? 42 | int size = Assets::GetContentPath().size(); 43 | return filename.substr(size, filename.size() - size); 44 | } 45 | 46 | std::string Asset::GetExtension() 47 | { 48 | std::string fn = GetName(); 49 | return fn.substr(fn.find_last_of(".") + 1); 50 | } 51 | 52 | /* 53 | void Asset::Load(const char *filename) 54 | { 55 | 56 | } 57 | 58 | void Asset::Unload() 59 | { 60 | 61 | } 62 | */ 63 | } 64 | -------------------------------------------------------------------------------- /Core/Asset.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | namespace Monocle 6 | { 7 | enum AssetType 8 | { 9 | ASSET_UNDEFINED, 10 | ASSET_TEXTURE, 11 | ASSET_AUDIO, 12 | ASSET_FONT, 13 | ASSET_MAX, 14 | }; 15 | 16 | //! Filter type for TextureAssets. 17 | enum FilterType 18 | { 19 | FILTER_NONE, 20 | FILTER_LINEAR 21 | }; 22 | 23 | //! \brief Base class for Asset types. 24 | //! 25 | //! Provides functions to manages filename and extensions, and reference counting for all derived AssetTypes. 26 | //! Derived classes must override void Reload(), void Unload(), and it is expected that they will have a 27 | //! void Load(const std::string &filename, ...) where ... is any additional necessary parameters. 28 | class Asset 29 | { 30 | public: 31 | //! Creates an Asset of the given type and initilizes the reference count to 0. Intended to be called by 32 | //! constructors of derived classes. 33 | Asset(AssetType type); 34 | virtual ~Asset() {} 35 | 36 | //! The filename associated with this asset. 37 | std::string filename; 38 | 39 | //! The type of this asset 40 | AssetType type; 41 | 42 | //! The number of references to this asset currently in use throughout the program. 43 | //! This number is incremented when this asset is requested through Assets::RequestTYPE() 44 | int referenceCount; // <- how many things use this 45 | 46 | //! 47 | bool isCached; // <- should we free ourselves? 48 | 49 | //! Increments the reference count of this asset. 50 | void AddReference(); 51 | //! Decrements the reference count of this asset. 52 | void RemoveReference(); 53 | //! Reloads this asset. This function is to be overridden by derived classes. 54 | //! Typically takes the form { Unload(); Load(); } 55 | virtual void Reload()=0; 56 | 57 | //! Returns the file path relative to the content path. 58 | std::string GetName(); 59 | //! Returns the file extension. 60 | std::string GetExtension(); // after the . : "booty.ogg" would return "ogg" 61 | 62 | protected: 63 | friend class Assets; 64 | // allow derived classes to add whatever params they want to load 65 | //virtual void Load(const std::string &filename)=0; 66 | //! Unloads the asset. Must be overriden by derived classes. 67 | virtual void Unload() = 0; 68 | }; 69 | } 70 | -------------------------------------------------------------------------------- /Core/Audio/AudioAsset.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // AudioAsset.cpp 3 | // MonocleTest 4 | // 5 | // Created by Josh Whelchel on 4/19/11. 6 | // 7 | 8 | #include "Audio.h" 9 | #include "AudioAsset.h" 10 | #include "../MonocleToolkit.h" 11 | #include "../Debug.h" 12 | 13 | #include 14 | #include // required for free and malloc (GCC) 15 | 16 | namespace Monocle 17 | { 18 | AudioAsset::AudioAsset() : Asset(ASSET_AUDIO) 19 | { 20 | size = 0; 21 | streamFromDisk = false; 22 | dataBuffer = 0; 23 | decodeString = ""; 24 | } 25 | 26 | /// Alec: Removed destructor. 27 | /// These objects get deleted when you call RemoveReference() (if the references run out) 28 | 29 | void AudioAsset::Load(const std::string &filename, bool streamFromDisk) 30 | { 31 | this->filename = filename; 32 | 33 | this->streamFromDisk = streamFromDisk; 34 | 35 | FILE *f; 36 | f = fopen(this->filename.c_str(),"rb"); 37 | 38 | if (!f){ 39 | Debug::Log("Asset " + filename + " was not found and cannot be loaded."); // ERROR 40 | return; 41 | } 42 | 43 | fseek(f,0,SEEK_END); 44 | size = ftell(f); 45 | fseek(f,0,SEEK_SET); 46 | 47 | if (!streamFromDisk){ 48 | // Load to memory! 49 | dataBuffer = malloc(size); 50 | fread(dataBuffer,size,1,f); 51 | 52 | Debug::Log("Commited " + StringOf(size) + " bytes to memory for " + GetName()); 53 | } 54 | 55 | fclose(f); 56 | } 57 | 58 | void AudioAsset::Reload() 59 | { 60 | Unload(); 61 | Load(this->filename,streamFromDisk); 62 | } 63 | 64 | void AudioAsset::Unload() 65 | { 66 | Debug::Log("Freeing audio memory for: " + this->filename); 67 | 68 | if (dataBuffer) 69 | { 70 | free(dataBuffer); 71 | dataBuffer = NULL; 72 | } 73 | } 74 | 75 | bool AudioAsset::IsStreaming() 76 | { 77 | return streamFromDisk; 78 | } 79 | 80 | void *AudioAsset::GetDataBuffer() 81 | { 82 | return dataBuffer; 83 | } 84 | 85 | long AudioAsset::GetDataSize() 86 | { 87 | return size; 88 | } 89 | 90 | void AudioAsset::SetDecodeString(std::string decodeString) 91 | { 92 | this->decodeString = decodeString; 93 | } 94 | 95 | std::string AudioAsset::GetDecodeString() 96 | { 97 | return this->decodeString; 98 | } 99 | 100 | void AudioAsset::Play( int loops, float volume, float pan, float pitch ) 101 | { 102 | Audio::PlaySound(this,loops,volume,pan,pitch); 103 | } 104 | } 105 | -------------------------------------------------------------------------------- /Core/Audio/AudioAsset.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "../Asset.h" 4 | #include "AudioDecoder.h" 5 | 6 | namespace Monocle 7 | { 8 | class AudioAsset : public Asset 9 | { 10 | public: 11 | AudioAsset(); 12 | 13 | /** 14 | Prepares the asset for decoding. 15 | 16 | @param streamFromDisk true if the asset should be streamed from disk or false if the asset should be loaded into memory. 17 | */ 18 | void Load( const std::string &filename, bool streamFromDisk ); 19 | void Reload(); 20 | void Unload(); 21 | 22 | /** 23 | @return true if the asset is to be streamed from disk 24 | */ 25 | bool IsStreaming(); 26 | 27 | /** 28 | If the asset isn't streaming from disk, this will return the pointer to the data buffer. 29 | 30 | @see GetDataSize() 31 | @return Pointer to the data. 32 | */ 33 | void *GetDataBuffer(); 34 | 35 | /** 36 | This returns the size in bytes of the asset, regardless of whether or not it is streaming from disk. 37 | 38 | @return the size in bytes of the asset, regardless of whether or not it is streaming from disk. 39 | */ 40 | long GetDataSize(); 41 | 42 | /** 43 | Sets the decode string for use by AudioCrypt. If the asset is not encoded, send "" 44 | */ 45 | void SetDecodeString( std::string decodeString ); 46 | 47 | std::string GetDecodeString(); 48 | 49 | /** 50 | Plays an audio file. The deck it plays on will be freed automatically when the sound is complete. 51 | 52 | @param loops Number of times to loop 53 | @param volume Volume, between 0.0 and 1.0 54 | @param pan Panning, between -1.0(L) and 1.0(R), 0.0 for center 55 | @param pitch Pitch, 0.5 - 2.0 56 | 57 | @see Audio::PlaySound 58 | */ 59 | void Play( int loops = 1, float volume = 1.0, float pan = 0.0, float pitch = 1.0 ); 60 | 61 | private: 62 | 63 | long size; 64 | bool streamFromDisk; 65 | void *dataBuffer; 66 | 67 | std::string decodeString; 68 | 69 | }; 70 | } -------------------------------------------------------------------------------- /Core/Audio/AudioAssetReader.h: -------------------------------------------------------------------------------- 1 | // 2 | // AudioAssetReader.h 3 | // 4 | // Created by Josh Whelchel on 4/27/11. 5 | // 6 | 7 | #pragma once 8 | 9 | #include "AudioAsset.h" 10 | #include "AudioCrypt.h" 11 | 12 | namespace Monocle { 13 | 14 | /* 15 | * AudioAssetReader is designed to include a file/memory pointer for reading from audio assets either on disk or in memory 16 | */ 17 | class AudioAssetReader 18 | { 19 | public: 20 | 21 | AudioAssetReader( AudioAsset *asset, std::string key = "" ); 22 | ~AudioAssetReader(); 23 | 24 | size_t SpaceUntilEOF(); 25 | size_t Read( void *dst, size_t size ); 26 | void Seek( size_t offset, int whence ); 27 | size_t Tell(); // Gets the position we're at (dataRead) 28 | 29 | private: 30 | 31 | // When Reading from Buffer 32 | char* dataPtr; // Pointer to the data in memory 33 | long dataSize; // Sizeo fo the data 34 | 35 | long dataRead; // How much data we have read so far 36 | 37 | // When Streaming 38 | FILE *file; 39 | 40 | AudioAsset *asset; 41 | AudioCryptKey *cryptKey; 42 | 43 | }; 44 | 45 | } -------------------------------------------------------------------------------- /Core/Audio/AudioCrypt.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | namespace Monocle 6 | { 7 | 8 | /** 9 | Encrypts and decrypts a data stream 10 | */ 11 | class AudioCryptKey 12 | { 13 | public: 14 | 15 | /** 16 | @param keyStr Decode string 17 | */ 18 | AudioCryptKey( std::string keyStr ); 19 | ~AudioCryptKey(void); 20 | 21 | /** 22 | Encodes an entire stream of data based on the key string. 23 | 24 | @param pData Data buffer 25 | @param nLength Length of data 26 | */ 27 | void EncodeStream( unsigned char *pData, unsigned long nLength ); 28 | 29 | /** 30 | Decodes an entire stream of data based on the key string. You cannot provide a stream that begins at an offset other than 5, 31 | and if the data is less than five bytes worth it will be assumed to be the END of the full stream of data. If this is not the case, 32 | use DecodeSlice5b(). 33 | 34 | @param pData Data buffer 35 | @param nLength Length of data 36 | */ 37 | void DecodeStream( unsigned char *pData, unsigned long nLength ); 38 | 39 | /** 40 | Decodes a slice of data in 5 byte chunks. This needs an entire 5 bytes plus more to look ahead and look behind (in order to align it 41 | to 5 byte slices in relation to the full stream of data. To achieve this, nLength specifies the length of the data you wish to 42 | alter, with nOffset providing how many bytes away from being a multiple of 5 origData points to. 43 | 44 | For instance, if origData begins on the 3rd byte, you should provide 3 for nOffset. If it is byte 7, you will provide 7%5 (= 2). 45 | 46 | lookAhead is responsible for notifying how many bytes of data are available to seek past the end of origData (you should provide 47 | the entire length remaining after nLength if possible, otherwise it simply needs to align to a full chunk of 5. When in doubt, read 48 | 5 bytes OR the space until EOF if less). 49 | 50 | @param origData Pointer to the original data to read. Will read also before this pointer nOffset bytes and beyond it up to 5 (or lookAhead if less). 51 | @param newData Pointer to a buffer of nLength size to fill with decoded data. 52 | @param lookAhead How many bytes exist after nLength in origData pointer that can be read. Will read up to 5, but should be less if EOF is sooner. 53 | @param nOffset How many bytes away from a multiple 5 origData starts at in the entirety of the datastream. This is usually just Tell()%5. 54 | */ 55 | void DecodeSlice5b(unsigned char *origData, unsigned char *newData, unsigned long nLength, unsigned long nOffset, unsigned long lookAhead=0); 56 | 57 | void ResetUses(); 58 | 59 | unsigned long m_lUses[4]; 60 | 61 | private: 62 | 63 | unsigned long m_nPart1; 64 | unsigned long m_nPart2; 65 | unsigned long m_nPart3; 66 | unsigned long m_nPart4; 67 | 68 | unsigned long m_bLookup1[ 256 ]; 69 | unsigned long m_bLookup2[ 256 ]; 70 | unsigned long m_bLookup3[ 256 ]; 71 | unsigned long m_bLookup4[ 256 ]; 72 | 73 | static void KeyStringToFourParts(char *cKeyStr, unsigned long *nPart1, unsigned long *nPart2, unsigned long *nPart3, unsigned long *nPart4); 74 | 75 | void DecodeSegment( unsigned char *newByte, unsigned char *oldByte ); 76 | void EncodeSegment( unsigned char *newByte, unsigned char *oldByte ); 77 | 78 | }; 79 | 80 | } -------------------------------------------------------------------------------- /Core/Audio/AudioDecoder.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include "Audio.h" 3 | #include "AudioDecoder.h" 4 | 5 | #include 6 | #include 7 | 8 | namespace Monocle 9 | { 10 | 11 | void AudioDecoder::Init( int samplerate, int bit, int ch ) 12 | { 13 | this->samplerate = samplerate; 14 | this->bit = bit; 15 | this->ch = ch; 16 | 17 | this->loopsRemaining = 0; 18 | this->outOfData = false; 19 | this->seekOffset = -1; 20 | this->total = 0; 21 | } 22 | 23 | AudioDecoder::~AudioDecoder() 24 | { 25 | 26 | } 27 | 28 | AudioDecoder::AudioDecoder( ) 29 | { 30 | 31 | } 32 | } -------------------------------------------------------------------------------- /Core/Audio/AudioVis.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | // 3 | // AudioVis.h 4 | // 5 | // Created by Josh Whelchel on 4/26/11. 6 | // 7 | 8 | #ifndef WINAPI 9 | #define WINAPI void 10 | #endif 11 | 12 | #include "VisCache2.h" 13 | 14 | namespace Monocle { 15 | // Contains visualization data (: 16 | 17 | class AudioVisData; 18 | 19 | class AudioVis 20 | { 21 | public: 22 | 23 | AudioVis(); 24 | ~AudioVis(); 25 | 26 | void PrepData(); 27 | 28 | // Vis Data 29 | float imm[2][16]; 30 | float avg[2][16]; 31 | float med_avg[2][16]; 32 | float long_avg[2][16]; 33 | 34 | unsigned char cWaveformR[576]; 35 | unsigned char cWaveformL[576]; 36 | float fWaveform[2][576]; 37 | float fSpectrum[2][512]; 38 | 39 | bool bClear; // True when vis should be clear. 40 | int bIsBeat; // 0 when not a beat, 1 on a beat (detected :3) 41 | 42 | long engineerData[4]; // Current data from the cache 43 | 44 | unsigned long updateCount; 45 | 46 | bool bDisabled; // This is set when the freuqnecy is changed. 47 | 48 | AudioVisData *data; 49 | 50 | void AnalyzeNewSound(long rsize); 51 | void BeatDetect(); 52 | 53 | int _usedCount; 54 | }; 55 | } -------------------------------------------------------------------------------- /Core/Audio/Decoders/OggDecoder.h: -------------------------------------------------------------------------------- 1 | #ifdef MONOCLE_AUDIO_OGG 2 | // 3 | // OggDecoder.h 4 | // MonocleTest 5 | // 6 | // Created by Josh Whelchel on 4/19/11. 7 | // 8 | 9 | #pragma once 10 | 11 | #include "../AudioDecoder.h" 12 | 13 | namespace Monocle 14 | { 15 | class OggDecoder : public AudioDecoder 16 | { 17 | public: 18 | 19 | OggDecoder( AudioAsset *asset ); 20 | ~OggDecoder(); 21 | 22 | virtual unsigned long Render( unsigned long size, void *outputBuffer ); 23 | 24 | void *oggData; 25 | 26 | AudioAsset *audAsset; 27 | }; 28 | } 29 | 30 | #endif -------------------------------------------------------------------------------- /Core/Audio/Decoders/WaveDecoder.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // WaveDecoder.cpp 3 | // 4 | // Created by Josh Whelchel on 4/28/11. 5 | // 6 | 7 | #include "WaveDecoder.h" 8 | 9 | namespace Monocle 10 | { 11 | /*** 12 | THIS CODE is responsible for registering this decoder with the file extension. 13 | See more info in Audio::Init. 14 | ***/ 15 | AudioDecoder *makeWaveFunc( AudioAsset *asset ) 16 | { 17 | return new WaveDecoder(asset); 18 | } 19 | 20 | static short WAVE_FORMAT_PCM = 0x0001; 21 | 22 | void WaveDecoder::WaveOpen() 23 | { 24 | char csID[10]; 25 | int fsize; 26 | int wfxsize; 27 | int datasize; 28 | WAVEFORMATEX *wfx = &format; 29 | 30 | csID[4] = 0; 31 | reader->Read(csID,4); 32 | if (std::string (csID) != "RIFF"){ 33 | return; 34 | } 35 | 36 | reader->Read ((char*)&fsize, 4); 37 | reader->Read (csID, 4); 38 | if (std::string (csID) != "WAVE"){ 39 | std::string s (" is not a valid WAVE form-type."); 40 | throw s; 41 | } 42 | 43 | reader->Read (csID, 4); 44 | if (std::string (csID) != "fmt "){ 45 | std::string s (" does not have a valid wave-form chunk ID."); 46 | throw s; 47 | } 48 | 49 | reader->Read ((char*)&wfxsize, 4); 50 | reader->Read ((char*)wfx, wfxsize); 51 | if (wfx->wFormatTag != WAVE_FORMAT_PCM){ 52 | std::string s (" is not of type PCM wave format."); 53 | throw s; 54 | } 55 | 56 | reader->Read (csID, 4); 57 | if (std::string (csID) != "data"){ 58 | std::string s (" does not have a valid data chunk ID."); 59 | throw s; 60 | } 61 | 62 | reader->Read ((char*)&datasize, 4); 63 | 64 | // Should be at data... 65 | } 66 | 67 | WaveDecoder::WaveDecoder( AudioAsset *asset ) 68 | { 69 | this->audAsset = asset; 70 | reader = new AudioAssetReader(audAsset,audAsset->GetDecodeString()); 71 | 72 | WaveOpen(); 73 | 74 | Init(format.nSamplesPerSec,format.wBitsPerSample,format.nChannels); 75 | } 76 | 77 | unsigned long WaveDecoder::Render( unsigned long size, void *buf ) 78 | { 79 | size_t ret = reader->Read(buf, size); 80 | if (!ret) 81 | outOfData = true; 82 | 83 | return ret; 84 | } 85 | 86 | WaveDecoder::~WaveDecoder() 87 | { 88 | delete reader; 89 | } 90 | } 91 | 92 | 93 | 94 | 95 | -------------------------------------------------------------------------------- /Core/Audio/Decoders/WaveDecoder.h: -------------------------------------------------------------------------------- 1 | // 2 | // OggDecoder.h 3 | // MonocleTest 4 | // 5 | // Created by Josh Whelchel on 4/19/11. 6 | // 7 | 8 | #pragma once 9 | 10 | #include "../AudioDecoder.h" 11 | #include "../AudioAssetReader.h" 12 | 13 | typedef struct { 14 | short wFormatTag; 15 | short nChannels; 16 | int nSamplesPerSec; 17 | int nAvgBytesPerSec; 18 | short nBlockAlign; 19 | short wBitsPerSample; 20 | short cbSize; 21 | } WAVEFORMATEX; 22 | 23 | namespace Monocle 24 | { 25 | class WaveDecoder : public AudioDecoder 26 | { 27 | public: 28 | 29 | WaveDecoder( AudioAsset *asset ); 30 | ~WaveDecoder(); 31 | 32 | virtual unsigned long Render( unsigned long size, void *outputBuffer ); 33 | 34 | AudioAsset *audAsset; 35 | 36 | WAVEFORMATEX format; 37 | AudioAssetReader *reader; 38 | 39 | private: 40 | 41 | void WaveOpen(); 42 | }; 43 | } 44 | 45 | -------------------------------------------------------------------------------- /Core/Audio/VisCache2.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | namespace Monocle { 4 | 5 | typedef struct vc2_entry_s 6 | { 7 | // 576 8bit Stereo Samples 8 | unsigned char cWaveLeft[576]; 9 | unsigned char cWaveRight[576]; 10 | 11 | // With a recorded time 12 | unsigned long nPos; 13 | 14 | // Engineer Data (4 longs should be plenty) 15 | // (eg, want to store information on the current order of a module, etc) 16 | long engineerData[4]; 17 | 18 | bool isSet; 19 | } vc2_entry; 20 | 21 | /** 22 | A cache mechanism for syncing written audio data with when it is actually played through the speakers. 23 | */ 24 | class VisCache2 25 | { 26 | public: 27 | VisCache2(void); 28 | public: 29 | ~VisCache2(void); 30 | 31 | public: 32 | 33 | // Init with max latency in MS, Sample rate in Samples per Second 34 | void Init( long maxLatency, long srate ); 35 | void Clean(); 36 | void Reset(); 37 | 38 | // Sets data to be retrieved later at position "pos" in MS 39 | void SetWrittenTime( unsigned long pos ); 40 | 41 | void PutWaveLeft( unsigned char * data ); 42 | void PutWaveRight( unsigned char * data ); 43 | 44 | void SetEngineerData( long data1, long data2, long data3, long data4 ); 45 | 46 | void EndEntry(); 47 | 48 | // Gets the latent data at play position "pos" in MS 49 | // This will return 0 if it's nothing new 50 | int GetLatentData( unsigned long pos ); 51 | 52 | void GetWaveLeft(unsigned char *out); 53 | void GetWaveRight(unsigned char *out); 54 | 55 | void GetEngineerData( long *data1, long *data2, long *data3, long *data4 ); 56 | 57 | void Destroy(); 58 | 59 | private: 60 | 61 | long m_nBufLen; 62 | vc2_entry *m_buf; 63 | 64 | long m_lastIndex; 65 | long m_curIndex; 66 | long m_readIndex; 67 | }; 68 | } 69 | -------------------------------------------------------------------------------- /Core/Audio/fft.h: -------------------------------------------------------------------------------- 1 | /* 2 | LICENSE 3 | ------- 4 | Copyright (C) 1999-2002 Nullsoft, Inc. 5 | 6 | This source code is provided 'as-is', without any express or implied 7 | warranty. In no event will the authors be held liable for any damages 8 | arising from the use of this source code or the software it produces. 9 | 10 | Permission is granted to anyone to use this source code for any purpose, 11 | including commercial applications, and to alter it and redistribute it 12 | freely, subject to the following restrictions: 13 | 14 | 1. The origin of this source code must not be misrepresented; you must not 15 | claim that you wrote the original source code. If you use this source code 16 | in a product, an acknowledgment in the product documentation would be 17 | appreciated but is not required. 18 | 2. Altered source versions must be plainly marked as such, and must not be 19 | misrepresented as being the original source code. 20 | 3. This notice may not be removed or altered from any source distribution. 21 | */ 22 | 23 | #ifndef __NULLSOFT_DX8_PLUGIN_SHELL_FFT_H__ 24 | #define __NULLSOFT_DX8_PLUGIN_SHELL_FFT_H__ 1 25 | 26 | 27 | class FFT 28 | { 29 | public: 30 | FFT(); 31 | ~FFT(); 32 | void Init(int samples_in, int samples_out, int bEqualize=1, float envelope_power=1.0f); 33 | void time_to_frequency_domain(float *in_wavedata, float *out_spectraldata); 34 | int GetNumFreq() { return NFREQ; }; 35 | void CleanUp(); 36 | private: 37 | int m_ready; 38 | int m_samples_in; 39 | int NFREQ; 40 | 41 | void InitEnvelopeTable(float power); 42 | void InitEqualizeTable(); 43 | void InitBitRevTable(); 44 | void InitCosSinTable(); 45 | 46 | int *bitrevtable; 47 | float *envelope; 48 | float *equalize; 49 | float *temp1; 50 | float *temp2; 51 | float (*cossintable)[2]; 52 | }; 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | #endif -------------------------------------------------------------------------------- /Core/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | file(GLOB CORE_SRCS *.cpp) 2 | file(GLOB COLLIDERS_SRCS Colliders/*.cpp) 3 | file(GLOB GRAPHICS_SRCS Graphics/*.cpp) 4 | file(GLOB LEVELEDITOR_SRCS LevelEditor/*.cpp) 5 | file(GLOB OGMOSIS_SRCS Ogmosis/*.cpp) 6 | file(GLOB XML_SRCS XML/*.cpp) 7 | file(GLOB AUDIO_SRCS Audio/*.cpp) 8 | file(GLOB AUDIO_DECODER_SRCS Audio/Decoders/*.cpp) 9 | file(GLOB PUPPET_SRCS Puppet/*.cpp) 10 | 11 | set(CORE_SRCS ${CORE_SRCS} 12 | ${COLLIDERS_SRCS} 13 | ${GRAPHICS_SRCS} 14 | ${LEVELEDITOR_SRCS} 15 | ${OGMOSIS_SRCS} 16 | ${AUDIO_SRCS} 17 | ${AUDIO_DECODER_SRCS} 18 | ${PUPPET_SRCS} 19 | ) 20 | 21 | if(WINDOWS) 22 | file(GLOB WINDOWS_SRCS Windows/*.cpp) 23 | set(PLATFORM_SRCS ${PLATFORM_SRCS} ${WINDOWS_SRCS}) 24 | endif(WINDOWS) 25 | 26 | if(LINUX) 27 | include_directories(${X11_INCLUDE_DIR}) 28 | set(CORE_LINK ${CORE_LINK} ${X11_LIBRARIES}) 29 | file(GLOB LINUX_SRCS Linux/*.cpp) 30 | set(PLATFORM_SRCS ${PLATFORM_SRCS} ${LINUX_SRCS}) 31 | endif(LINUX) 32 | 33 | if(WITH_OPENGL) 34 | include_directories(${OPENGL_INCLUDE_DIR}) 35 | file(GLOB OPENGL_SRCS 36 | OpenGL/*.cpp 37 | OpenGL/*.c 38 | OpenGL/GL/*.c 39 | ) 40 | set(CORE_LINK ${CORE_LINK} ${OPENGL_LIBRARIES}) 41 | set(CORE_SRCS ${CORE_SRCS} ${OPENGL_SRCS}) 42 | endif(WITH_OPENGL) 43 | 44 | if(WITH_OPENAL) 45 | include_directories(${OPENAL_INCLUDE_DIR}) 46 | file(GLOB OPENAL_SRCS OpenAL/*.cpp) 47 | set(CORE_LINK ${CORE_LINK} ${OPENAL_LIBRARY}) 48 | set(CORE_SRCS ${CORE_SRCS} ${OPENAL_SRCS}) 49 | endif(WITH_OPENAL) 50 | 51 | if(WITH_AUDIOWAVE) 52 | file(GLOB WAVE_SRCS Audio/wave/*.cpp) 53 | set(CORE_SRCS ${CORE_SRCS} ${WAVE_SRCS}) 54 | endif(WITH_AUDIOWAVE) 55 | 56 | if(WITH_AUDIOOGG) 57 | include_directories(${OGGVORBIS_INCLUDE_DIR}) 58 | set(CORE_LINK ${CORE_LINK} ${OGGVORBIS_LIBRARIES}) 59 | endif(WITH_AUDIOOGG) 60 | 61 | add_library(MonocleCore 62 | ${CORE_SRCS} 63 | ${PLATFORM_SRCS} 64 | ) 65 | add_library(TinyXML ${XML_SRCS}) 66 | 67 | target_link_libraries(MonocleCore TinyXML ${CORE_LINK}) 68 | 69 | if(BUILD_TESTS) 70 | add_subdirectory(Tests) 71 | endif(BUILD_TESTS) 72 | -------------------------------------------------------------------------------- /Core/Camera.cpp: -------------------------------------------------------------------------------- 1 | #include "Camera.h" 2 | #include "Graphics.h" 3 | 4 | namespace Monocle 5 | { 6 | Camera::Camera(const Camera& camera) 7 | : Transform(camera), isVisible(camera.isVisible), frontLayer(camera.frontLayer), backLayer(camera.backLayer) 8 | { 9 | 10 | } 11 | 12 | Camera::Camera() 13 | : Transform(), isVisible(true), frontLayer(-100), backLayer(100) 14 | { 15 | position = Graphics::GetScreenCenter(); 16 | } 17 | 18 | void Camera::ApplyMatrix() 19 | { 20 | //Graphics::IdentityMatrix(); 21 | Graphics::DefaultMatrix(); 22 | Graphics::Scale(scale); 23 | Graphics::Translate(position * -1.0f); 24 | Graphics::Rotate(rotation, 0, 0, 1); 25 | } 26 | 27 | void Camera::SetLayers(int backLayer, int frontLayer) 28 | { 29 | this->frontLayer = frontLayer; 30 | this->backLayer = backLayer; 31 | } 32 | 33 | int Camera::GetBackLayer() 34 | { 35 | return backLayer; 36 | } 37 | 38 | int Camera::GetFrontLayer() 39 | { 40 | return frontLayer; 41 | } 42 | } -------------------------------------------------------------------------------- /Core/Camera.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "Transform.h" 4 | 5 | namespace Monocle 6 | { 7 | //! \brief Manages the details of a view through which items in a scene are rendered. 8 | //! Cameras are the eyes of the engine, their position, rotation, and depth of vision determine what is rendered 9 | //! onto the screen. 10 | class Camera : public Transform 11 | { 12 | public: 13 | Camera(); 14 | Camera(const Camera& camera); 15 | 16 | //! Applies the position translation, scale, and rotation of this camera to the graphics context. 17 | void ApplyMatrix(); 18 | 19 | //! Sets the layers that this camera can see. 20 | //! \param backLayer The deepest layer in this camera's vision 21 | //! \param frontLayer The shallowest layer in this camera's vision 22 | void SetLayers(int backLayer, int frontLayer); 23 | //! Returns the deepest layer the camera can see 24 | int GetBackLayer(); 25 | //! Returns the shallowest layer the camera can see 26 | int GetFrontLayer(); 27 | 28 | //! Whether or not the camera is to be rendered 29 | bool isVisible; 30 | 31 | private: 32 | int backLayer, frontLayer; 33 | }; 34 | } 35 | -------------------------------------------------------------------------------- /Core/Cocoa/CocoaEvents.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | extern void Cocoa_RegisterApp(void); 4 | extern void Cocoa_PumpEvents(); 5 | 6 | -------------------------------------------------------------------------------- /Core/Cocoa/CocoaKeys.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | void Cocoa_HandleKeyEvent(NSEvent *event); 4 | 5 | -------------------------------------------------------------------------------- /Core/Cocoa/CocoaOpenGL.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | extern NSOpenGLContext* Cocoa_GL_CreateContext(); 6 | extern int Cocoa_GL_MakeCurrent(NSWindow* window, NSOpenGLContext* context); 7 | extern void Cocoa_GL_SwapWindow(); 8 | extern void Cocoa_GL_DeleteContext(NSOpenGLContext* context); 9 | extern int Cocoa_GL_SetSwapInterval(int interval); 10 | extern int Cocoa_GL_GetSwapInterval(); 11 | 12 | /* vi: set ts=4 sw=4 noexpandtab: */ 13 | 14 | -------------------------------------------------------------------------------- /Core/Cocoa/CocoaPlatform.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "../Platform.h" 4 | #include "CocoaWindowListener.h" 5 | 6 | #include 7 | 8 | namespace Monocle 9 | { 10 | class CocoaPlatform 11 | { 12 | public: 13 | static CocoaPlatform* instance; 14 | static Platform* platform; 15 | 16 | ~CocoaPlatform(); 17 | 18 | void Init(const std::string &name, int w, int h, int bits, bool fullscreen); 19 | 20 | NSWindow* window; 21 | WindowData* windowData; 22 | 23 | std::string bundleResourcesPath; 24 | }; 25 | } 26 | 27 | /* vi: set ts=4 sw=4 noexpandtab: */ 28 | 29 | -------------------------------------------------------------------------------- /Core/Cocoa/CocoaWindowListener.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #import 4 | 5 | typedef struct WindowData WindowData; 6 | 7 | #if MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_6 8 | @interface CocoaWindowListener : NSResponder { 9 | #else 10 | @interface CocoaWindowListener : NSResponder { 11 | #endif 12 | WindowData* _data; 13 | } 14 | 15 | -(void) listen:(WindowData *) data; 16 | -(void) close; 17 | 18 | /* Window delegate functionality */ 19 | -(BOOL) windowShouldClose:(id) sender; 20 | -(void) windowDidResize:(NSNotification *) aNotification; 21 | 22 | /* Window event handling */ 23 | -(void) mouseDown:(NSEvent *) theEvent; 24 | -(void) rightMouseDown:(NSEvent *) theEvent; 25 | -(void) otherMouseDown:(NSEvent *) theEvent; 26 | -(void) mouseUp:(NSEvent *) theEvent; 27 | -(void) rightMouseUp:(NSEvent *) theEvent; 28 | -(void) otherMouseUp:(NSEvent *) theEvent; 29 | -(void) mouseEntered:(NSEvent *)theEvent; 30 | -(void) mouseExited:(NSEvent *)theEvent; 31 | -(void) mouseMoved:(NSEvent *) theEvent; 32 | -(void) mouseDragged:(NSEvent *) theEvent; 33 | -(void) rightMouseDragged:(NSEvent *) theEvent; 34 | -(void) otherMouseDragged:(NSEvent *) theEvent; 35 | -(void) scrollWheel:(NSEvent *) theEvent; 36 | 37 | /* Touch event handling */ 38 | typedef enum { 39 | COCOA_TOUCH_DOWN, 40 | COCOA_TOUCH_UP, 41 | COCOA_TOUCH_MOVE, 42 | COCOA_TOUCH_CANCELLED 43 | } cocoaTouchType; 44 | -(void) handleTouches:(cocoaTouchType)type withEvent:(NSEvent*) event; 45 | 46 | @end 47 | 48 | struct WindowData 49 | { 50 | bool created; 51 | NSWindow *nswindow; 52 | CocoaWindowListener *listener; 53 | }; 54 | 55 | void Cocoa_DestroyWindow(WindowData* data); 56 | 57 | -------------------------------------------------------------------------------- /Core/Colliders/CircleCollider.cpp: -------------------------------------------------------------------------------- 1 | #include "CircleCollider.h" 2 | #include "../CollisionData.h" 3 | #include 4 | 5 | namespace Monocle 6 | { 7 | CircleCollider::CircleCollider(float radius, Vector2 offset) 8 | : Collider() 9 | { 10 | this->offset = offset; 11 | this->radius = radius; 12 | } 13 | 14 | ColliderType CircleCollider::GetColliderType() 15 | { 16 | return CT_CIRCLE; 17 | } 18 | 19 | bool CircleCollider::IntersectsPoint(const Vector2& point, CollisionData *collisionData) 20 | { 21 | Vector2 ePos = GetEntityPosition(); 22 | 23 | Vector2 diff = point - (ePos + offset); 24 | return (diff.IsInRange(radius)); 25 | } 26 | 27 | bool CircleCollider::IntersectsLine(const Vector2& start, const Vector2& end, float lineRadius, CollisionData *collisionData) 28 | { 29 | //Algorithm stolen from: http://www.gamedev.net/topic/304578-finite-line-circle-intersection/page__view__findpost__p__2938618 30 | 31 | Vector2 ePos = GetEntityPosition(); 32 | 33 | Vector2 dir = end - start; 34 | Vector2 diff = (ePos + offset) - start; 35 | float t = diff.Dot(dir) / dir.GetSquaredMagnitude(); 36 | if (t < 0.0f) 37 | t = 0.0f; 38 | if (t > 1.0f) 39 | t = 1.0f; 40 | Vector2 closest = (t * dir) + start; 41 | Vector2 d = (ePos + offset) - closest; 42 | 43 | bool didCollide = d.GetSquaredMagnitude() <= (radius + lineRadius) * (radius + lineRadius); 44 | 45 | if (didCollide && collisionData) 46 | { 47 | Vector2 diff = start - ePos; 48 | diff.Clamp(radius); 49 | collisionData->hitPoint = ePos + diff; 50 | collisionData->penetration = fabs(d.GetMagnitude() - (radius + lineRadius)); 51 | collisionData->normal = (ePos - closest).GetNormalized(); 52 | collisionData->collider = this; 53 | } 54 | 55 | return didCollide; 56 | } 57 | 58 | float CircleCollider::GetCenterX(bool relativeToEntity) 59 | { 60 | if (relativeToEntity) 61 | return offset.x; 62 | else 63 | return GetEntityPosition().x + offset.x; 64 | } 65 | 66 | float CircleCollider::GetCenterY(bool relativeToEntity) 67 | { 68 | if (relativeToEntity) 69 | return offset.y; 70 | else 71 | return GetEntityPosition().y + offset.y; 72 | } 73 | 74 | Vector2 CircleCollider::GetCenter(bool relativeToEntity) 75 | { 76 | return Vector2(GetCenterX(relativeToEntity), GetCenterY(relativeToEntity)); 77 | } 78 | } -------------------------------------------------------------------------------- /Core/Colliders/CircleCollider.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "Collider.h" 4 | #include "../Vector2.h" 5 | #include "../Entity.h" 6 | 7 | namespace Monocle 8 | { 9 | class CircleCollider : public Collider 10 | { 11 | public: 12 | float radius; 13 | CircleCollider(float radius, Vector2 offset=Vector2::zero); 14 | ColliderType GetColliderType(); 15 | bool IntersectsPoint(const Vector2& point, CollisionData *collisionData = NULL); 16 | bool IntersectsLine(const Vector2& start, const Vector2& end, float lineRadius = 1.0f, CollisionData *collisionData = NULL); 17 | 18 | float GetCenterX(bool relativeToEntity = false); 19 | float GetCenterY(bool relativeToEntity = false); 20 | Vector2 GetCenter(bool relativeToEntity = false); 21 | }; 22 | } -------------------------------------------------------------------------------- /Core/Colliders/Collider.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "../Vector2.h" 4 | // for NULL 5 | #include 6 | 7 | namespace Monocle 8 | { 9 | enum ColliderType 10 | { 11 | CT_RECT=0, 12 | CT_CIRCLE, 13 | CT_POLYGON, 14 | CT_PATH 15 | }; 16 | 17 | class RectangleCollider; 18 | class CircleCollider; 19 | class PolygonCollider; 20 | class LineSegmentCollider; 21 | class PathCollider; 22 | class Entity; 23 | class CollisionData; 24 | 25 | class Collider 26 | { 27 | public: 28 | Collider(); 29 | 30 | void SetEntity(Entity* entity); 31 | Entity* GetEntity(); 32 | Vector2 GetEntityPosition(); 33 | 34 | Vector2 offset; 35 | 36 | virtual ColliderType GetColliderType() = 0; 37 | virtual bool IntersectsPoint(const Vector2& point, CollisionData *collisionData=NULL)=0; 38 | virtual bool IntersectsLine(const Vector2& start, const Vector2& end, float lineRadius = 0.0f, CollisionData *collisionData=NULL)=0; 39 | 40 | static bool Collide(Collider* a, Collider* b, CollisionData *collisionData = NULL); 41 | static bool LinesIntersect(const Vector2& aStart, const Vector2& aEnd, const Vector2& bStart, const Vector2& bEnd, CollisionData *collisionData=NULL); 42 | 43 | private: 44 | Entity *entity; 45 | static bool CollideRectRect(RectangleCollider* a, RectangleCollider* b, CollisionData *collisionData); 46 | static bool CollideCircleCircle(CircleCollider* a, CircleCollider* b, CollisionData *collisionData); 47 | static bool CollidePolygonPolygon(PolygonCollider* a, PolygonCollider* b, CollisionData *collisionData); 48 | 49 | static bool CollideRectCircle(RectangleCollider* a, CircleCollider* b, CollisionData *collisionData); 50 | static bool CollideRectPolygon(RectangleCollider* a, PolygonCollider* b, CollisionData *collisionData); 51 | static bool CollideCirclePolygon(CircleCollider* a, PolygonCollider* b, CollisionData *collisionData); 52 | 53 | static bool CollideCirclePath(CircleCollider *a, PathCollider *b, CollisionData *collisionData); 54 | }; 55 | } -------------------------------------------------------------------------------- /Core/Colliders/PathCollider.cpp: -------------------------------------------------------------------------------- 1 | #include "PathCollider.h" 2 | #include "CollisionData.h" 3 | 4 | namespace Monocle 5 | { 6 | PathCollider::PathCollider() 7 | : Collider(), startNode(NULL), radius(0.0f) 8 | { 9 | } 10 | 11 | PathCollider::PathCollider(Node *node, float radius) 12 | : Collider(), startNode(node), radius(radius) 13 | { 14 | } 15 | 16 | ColliderType PathCollider::GetColliderType() 17 | { 18 | return CT_PATH; 19 | } 20 | 21 | bool PathCollider::IntersectsPoint(const Vector2& point, CollisionData *collisionData) 22 | { 23 | return false; 24 | } 25 | 26 | // ignores radius for now 27 | bool PathCollider::IntersectsLine(const Vector2& start, const Vector2& end, float radius, CollisionData *collisionData) 28 | { 29 | Node *node = startNode; 30 | while(node) 31 | { 32 | Node *next = node->GetNext(); 33 | if (next) 34 | { 35 | if (node->variant != -1) 36 | { 37 | if (LinesIntersect(node->GetWorldPosition(), next->GetWorldPosition(), start, end, collisionData)) 38 | { 39 | collisionData->collider = this; 40 | return true; 41 | } 42 | } 43 | } 44 | node = next; 45 | } 46 | return false; 47 | } 48 | } -------------------------------------------------------------------------------- /Core/Colliders/PathCollider.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "Collider.h" 4 | #include "../LevelEditor/Node.h" 5 | 6 | namespace Monocle 7 | { 8 | class PathCollider : public Collider 9 | { 10 | public: 11 | PathCollider(); 12 | PathCollider(Node *node, float radius); 13 | ColliderType GetColliderType(); 14 | bool IntersectsPoint(const Vector2& point, CollisionData *collisionData = NULL); 15 | bool IntersectsLine(const Vector2& start, const Vector2& end, float lineRadius = 1.0f, CollisionData *collisionData = NULL); 16 | 17 | Node *startNode; 18 | 19 | float radius; 20 | }; 21 | } -------------------------------------------------------------------------------- /Core/Colliders/PolygonCollider.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "Collider.h" 4 | #include "../Vector2.h" 5 | #include "../Entity.h" 6 | #include 7 | 8 | namespace Monocle 9 | { 10 | // Arbitrary, possibly concave polygon 11 | class PolygonCollider : public Collider 12 | { 13 | public: 14 | std::vector points; 15 | PolygonCollider(Vector2 offset=Vector2::zero); 16 | ColliderType GetColliderType(); 17 | bool IntersectsPoint(const Vector2& point); 18 | bool IntersectsLine(const Vector2& start, const Vector2& end, float lineRadius = 1.0f); 19 | 20 | bool IsEmpty(); 21 | void AddPoint(Vector2 point); 22 | int GetPointCount(); 23 | Vector2 GetPoint(int index, bool relativeToEntity = false); 24 | 25 | float GetLeftmost(bool relativeToEntity = false); 26 | float GetRightmost(bool relativeToEntity = false); 27 | float GetTopmost(bool relativeToEntity = false); 28 | float GetBottommost(bool relativeToEntity = false); 29 | 30 | private: 31 | float leftmost; 32 | float rightmost; 33 | float topmost; 34 | float bottommost; 35 | }; 36 | } -------------------------------------------------------------------------------- /Core/Colliders/RectangleCollider.cpp: -------------------------------------------------------------------------------- 1 | #include "RectangleCollider.h" 2 | 3 | namespace Monocle 4 | { 5 | //Note: collision is centered 6 | // so 0,0 is the center of the sprite 7 | // unless you set an offset (position) 8 | 9 | RectangleCollider::RectangleCollider(float width, float height, Vector2 offset) 10 | : Collider() 11 | { 12 | this->offset = offset; 13 | this->width = width; 14 | this->height = height; 15 | } 16 | 17 | ColliderType RectangleCollider::GetColliderType() 18 | { 19 | return CT_RECT; 20 | } 21 | 22 | bool RectangleCollider::IntersectsPoint(const Vector2& point, CollisionData *collisionData) 23 | { 24 | //Vector2 ePos = GetEntityPosition(); 25 | 26 | return (point.x > GetLeft() && point.y > GetTop() && point.x < GetRight() && point.y < GetBottom()); 27 | } 28 | 29 | bool RectangleCollider::IntersectsLine(const Vector2& start, const Vector2& end, float lineRadius, CollisionData *collisionData) 30 | { 31 | //TODO: Support line width! 32 | 33 | if (!collisionData) 34 | { 35 | if (IntersectsPoint(start) || IntersectsPoint(end)) 36 | return true; 37 | } 38 | 39 | Vector2 pA = GetTopLeft(); 40 | Vector2 pB = GetTopRight(); 41 | Vector2 pC = GetBottomRight(); 42 | Vector2 pD = GetBottomLeft(); 43 | 44 | return (LinesIntersect(start, end, pA, pB, collisionData) || LinesIntersect(start, end, pB, pC, collisionData) || LinesIntersect(start, end, pC, pD, collisionData) || LinesIntersect(start, end, pD, pA, collisionData)); 45 | } 46 | 47 | float RectangleCollider::GetRight(bool relativeToEntity) 48 | { 49 | if (relativeToEntity) 50 | return offset.x + width*0.5; 51 | else 52 | return GetEntityPosition().x + offset.x + width*0.5; 53 | } 54 | 55 | float RectangleCollider::GetLeft(bool relativeToEntity) 56 | { 57 | if (relativeToEntity) 58 | return offset.x - width*0.5f; 59 | else 60 | return GetEntityPosition().x + offset.x - width*0.5; 61 | } 62 | 63 | float RectangleCollider::GetTop(bool relativeToEntity) 64 | { 65 | if (relativeToEntity) 66 | return offset.y - height*0.5f; 67 | else 68 | return GetEntityPosition().y + offset.y - height*0.5f; 69 | } 70 | 71 | float RectangleCollider::GetBottom(bool relativeToEntity) 72 | { 73 | if (relativeToEntity) 74 | return offset.y + height*0.5f; 75 | else 76 | return GetEntityPosition().y + offset.y + height*0.5f; 77 | } 78 | 79 | Vector2 RectangleCollider::GetTopLeft(bool relativeToEntity) 80 | { 81 | return Vector2(GetLeft(relativeToEntity), GetTop(relativeToEntity)); 82 | } 83 | 84 | Vector2 RectangleCollider::GetTopRight(bool relativeToEntity) 85 | { 86 | return Vector2(GetRight(relativeToEntity), GetTop(relativeToEntity)); 87 | } 88 | 89 | Vector2 RectangleCollider::GetBottomLeft(bool relativeToEntity) 90 | { 91 | return Vector2(GetLeft(relativeToEntity), GetBottom(relativeToEntity)); 92 | } 93 | 94 | Vector2 RectangleCollider::GetBottomRight(bool relativeToEntity) 95 | { 96 | return Vector2(GetRight(relativeToEntity), GetBottom(relativeToEntity)); 97 | } 98 | } -------------------------------------------------------------------------------- /Core/Colliders/RectangleCollider.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "Collider.h" 4 | #include "../Vector2.h" 5 | #include "../Entity.h" 6 | 7 | namespace Monocle 8 | { 9 | // Axis-Aligned Bounding Box 10 | class RectangleCollider : public Collider 11 | { 12 | public: 13 | float width; 14 | float height; 15 | RectangleCollider(float width, float height, Vector2 offset=Vector2::zero); 16 | ColliderType GetColliderType(); 17 | bool IntersectsPoint(const Vector2& point, CollisionData *collisionData = NULL); 18 | bool IntersectsLine(const Vector2& start, const Vector2& end, float lineRadius = 0.0f, CollisionData *collisionData=NULL); 19 | 20 | float GetRight(bool relativeToEntity = false); 21 | float GetLeft(bool relativeToEntity = false); 22 | float GetTop(bool relativeToEntity = false); 23 | float GetBottom(bool relativeToEntity = false); 24 | 25 | Vector2 GetTopLeft(bool relativeToEntity = false); 26 | Vector2 GetTopRight(bool relativeToEntity = false); 27 | Vector2 GetBottomLeft(bool relativeToEntity = false); 28 | Vector2 GetBottomRight(bool relativeToEntity = false); 29 | }; 30 | } -------------------------------------------------------------------------------- /Core/Collision.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "Colliders/Collider.h" 4 | #include "Colliders/RectangleCollider.h" 5 | #include "Colliders/CircleCollider.h" 6 | 7 | #include "CollisionData.h" 8 | 9 | #include 10 | #include 11 | #include 12 | 13 | namespace Monocle 14 | { 15 | class Entity; 16 | 17 | //! 18 | //! \brief Manages collision for Monocle. In most cases there is no need to reference this class, use the Entity::Collide function instead. 19 | //! 20 | //! Collision tracks Collider instances, and uses their Entity pointers to check for which entities fit the tag description passed to Collision::Collide. 21 | //! 22 | class Collision 23 | { 24 | public: 25 | //! Returns the first Collider with the specified tag that intersects with the line. 26 | //! \param start The beginning vector of the line to cast. 27 | //! \param end The end vector of the line to cast. 28 | //! \param radius The radius of the line to cast. 29 | //! \param tag The tag of the Colliders to be checked for intersection 30 | //! \param collisionData [out] The data resulting from the collision 31 | static Collider* LineCast(const Vector2 &start, const Vector2 &end, float radius, const std::string &tag, CollisionData *collisionData = NULL); 32 | 33 | private: 34 | friend class Entity; 35 | friend class Game; 36 | 37 | Collision(); 38 | void Init(); 39 | 40 | static void RegisterColliderWithEntity(Collider *collider, Entity *entity); 41 | static void RemoveCollider(Collider *collider); 42 | static Collider* Collide(Entity *entity, const std::string &tag, CollisionData *collisionData=NULL); 43 | static Collider* Collide(Collider *collider, const std::string &tag, CollisionData *collisionData=NULL); 44 | 45 | private: 46 | static Collision *instance; 47 | std::list colliders; 48 | }; 49 | } 50 | -------------------------------------------------------------------------------- /Core/CollisionData.cpp: -------------------------------------------------------------------------------- 1 | #include "CollisionData.h" 2 | 3 | namespace Monocle 4 | { 5 | CollisionData::CollisionData() 6 | : penetration(0.0f), collider(NULL) 7 | { 8 | } 9 | } -------------------------------------------------------------------------------- /Core/CollisionData.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "Vector2.h" 4 | #include "Colliders/Collider.h" 5 | 6 | namespace Monocle 7 | { 8 | //! Describes the result of a collision. Used to resolve collisions. 9 | class CollisionData 10 | { 11 | public: 12 | CollisionData(); 13 | 14 | //! Position where the collision occurred 15 | Vector2 hitPoint; 16 | //! Normal of the collision 17 | Vector2 normal; 18 | //! How far into the collider we've moved 19 | float penetration; 20 | //! Pointer to the collider that was hit 21 | Collider *collider; 22 | }; 23 | } 24 | -------------------------------------------------------------------------------- /Core/Color.cpp: -------------------------------------------------------------------------------- 1 | #include "Color.h" 2 | #include 3 | 4 | namespace Monocle 5 | { 6 | Color Color::white = Color(1,1,1,1); 7 | Color Color::grey = Color(0.5f, 0.5f, 0.5f, 1.0f); 8 | 9 | Color Color::black = Color(0,0,0,1); 10 | Color Color::red = Color(1,0,0,1); 11 | Color Color::green = Color(0,1,0,1); 12 | Color Color::blue = Color(0,0,1,1); 13 | Color Color::yellow = Color(1,1,0,1); 14 | Color Color::orange = Color(1.0f,0.5f,0.0f,1.0f); 15 | Color Color::purple = Color(0.5f, 0.0f, 1.0f, 1.0f); 16 | 17 | Color::Color(const Color &color) 18 | : r(color.r), g(color.g), b(color.b), a(color.a) 19 | { 20 | } 21 | 22 | Color::Color() 23 | : r(1), g(1), b(1), a(1) 24 | { 25 | 26 | } 27 | 28 | Color::Color(float r, float g, float b, float a) 29 | : r(r), g(g), b(b), a(a) 30 | { 31 | 32 | } 33 | 34 | Color::Color(const std::string &hexString) 35 | { 36 | std::istringstream is(hexString); 37 | 38 | unsigned int hexcolor; 39 | is >> std::hex >> hexcolor; 40 | 41 | r = ( hexcolor >> 16 ) & 0xFF; 42 | g = ( hexcolor >> 8 ) & 0xFF; 43 | b = hexcolor & 0xFF; 44 | r /= 255.0f; 45 | g /= 255.0f; 46 | b /= 255.0f; 47 | a = 1.0f; 48 | } 49 | 50 | bool Color::operator==(const Color& rhs) 51 | { 52 | return ((r == rhs.r) && (g == rhs.g) && (b == rhs.b) && (a == rhs.a)); 53 | } 54 | 55 | bool Color::operator!=(const Color& rhs) 56 | { 57 | return ((r != rhs.r) || (g != rhs.g) || (b != rhs.b) || (a != rhs.a)); 58 | } 59 | 60 | void Color::Clamp() 61 | { 62 | for (unsigned int i = 0; i < 4; i++) 63 | { 64 | if ((*this)[i] > 1.0f) 65 | (*this)[i] = 1.0f; 66 | if ((*this)[i] < 0.0f) 67 | (*this)[i] = 0.0f; 68 | } 69 | } 70 | 71 | float& Color::operator[] (unsigned int i) 72 | { 73 | switch(i) 74 | { 75 | case 0: return r; 76 | case 1: return g; 77 | case 2: return b; 78 | default: return a; 79 | } 80 | } 81 | 82 | Color operator+(const Color& lhs, const Color& rhs) 83 | { 84 | return Color(lhs.r + rhs.r, lhs.g + rhs.g, lhs.b + rhs.b, lhs.a + rhs.a); 85 | } 86 | 87 | Color operator-(const Color& lhs, const Color& rhs) 88 | { 89 | return Color(lhs.r - rhs.r, lhs.g - rhs.g, lhs.b - rhs.b, lhs.a - rhs.a); 90 | } 91 | 92 | Color operator*(float lhs, const Color& rhs) // left scalar multiplication 93 | { 94 | return Color(lhs * rhs.r, lhs * rhs.g, lhs * rhs.b, lhs * rhs.a); 95 | } 96 | 97 | Color operator*(const Color& lhs, float rhs) // right scalar multiplication 98 | { 99 | return Color(lhs.r * rhs, lhs.g * rhs, lhs.b * rhs, lhs.a * rhs); 100 | } 101 | 102 | Color operator/(const Color& lhs, float rhs) 103 | { 104 | return Color(lhs.r / rhs, lhs.g / rhs, lhs.b / rhs, lhs.a / rhs); 105 | } 106 | } 107 | -------------------------------------------------------------------------------- /Core/Color.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | namespace Monocle 6 | { 7 | //! Describes a color using 4 floats in 0.0 - 1.0 range. 8 | class Color 9 | { 10 | public: 11 | Color(const Color &color); 12 | Color(); 13 | Color(float r, float g, float b, float a); 14 | Color(const std::string &hexString); 15 | 16 | //! Clamps the rgba values to between 0 and 1.0, inclusive. 17 | void Clamp(); 18 | 19 | //! Indirect accessor for rgba values. Color[0] = r, [1] = g, [2] = b, [3] = a, [4+] = undefined 20 | float& operator[] (unsigned int i); 21 | bool operator==(const Color& rhs); 22 | bool operator!=(const Color& rhs); 23 | 24 | //! Red, green, blue, alpha (translucency) 25 | float r, g, b, a; 26 | 27 | static Color white; 28 | static Color grey; 29 | static Color black; 30 | static Color red; 31 | static Color green; 32 | static Color blue; 33 | static Color yellow; 34 | static Color orange; 35 | static Color purple; 36 | }; 37 | 38 | Color operator+(const Color& lhs, const Color& rhs); 39 | Color operator-(const Color& lhs, const Color& rhs); 40 | Color operator*(float lhs, const Color& rhs); // left scalar multiplication 41 | Color operator*(const Color& lhs, float rhs); // right scalar multiplication 42 | Color operator/(const Color& lhs, float rhs); 43 | 44 | } 45 | -------------------------------------------------------------------------------- /Core/ConfigValues.cpp: -------------------------------------------------------------------------------- 1 | #include "ConfigValues.h" 2 | 3 | namespace Monocle 4 | { 5 | ConfigValues *ConfigValues::instance = NULL; 6 | 7 | ConfigValues::ConfigValues() 8 | { 9 | instance = this; 10 | } 11 | 12 | void ConfigValues::Load(const std::string &filename) 13 | { 14 | TiXmlDocument doc; 15 | doc.LoadFile(Assets::GetContentPath() + filename); 16 | TiXmlElement *xmlValues = doc.FirstChildElement("config"); 17 | if (xmlValues) 18 | { 19 | TiXmlElement *xmlValue = xmlValues->FirstChildElement("value"); 20 | while (xmlValue) 21 | { 22 | std::string name = XMLReadString(xmlValue, "name"); 23 | 24 | if (xmlValue->Attribute("float")) 25 | instance->floats[name] = XMLReadFloat(xmlValue, "float"); 26 | 27 | if (xmlValue->Attribute("string")) 28 | instance->strings[name] = XMLReadString(xmlValue, "string"); 29 | 30 | if (xmlValue->Attribute("int")) 31 | instance->ints[name] = XMLReadInt(xmlValue, "int"); 32 | 33 | if (xmlValue->Attribute("bool")) 34 | instance->bools[name] = XMLReadBool(xmlValue, "bool"); 35 | 36 | if (xmlValue->Attribute("vector2")) 37 | instance->vector2s[name] = XMLReadVector2(xmlValue, "vector2"); 38 | 39 | xmlValue = xmlValue->NextSiblingElement("value"); 40 | } 41 | } 42 | } 43 | 44 | std::string ConfigValues::GetString(const std::string &valueName) 45 | { 46 | return instance->strings[valueName]; 47 | } 48 | 49 | int ConfigValues::GetInt(const std::string &valueName) 50 | { 51 | return instance->ints[valueName]; 52 | } 53 | 54 | float ConfigValues::GetFloat(const std::string &valueName) 55 | { 56 | return instance->floats[valueName]; 57 | } 58 | 59 | bool ConfigValues::GetBool(const std::string &valueName) 60 | { 61 | return instance->bools[valueName]; 62 | } 63 | 64 | Vector2 ConfigValues::GetVector2(const std::string &valueName) 65 | { 66 | return instance->vector2s[valueName]; 67 | } 68 | } -------------------------------------------------------------------------------- /Core/ConfigValues.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include "Vector2.h" 6 | #include "Monocle.h" 7 | 8 | namespace Monocle 9 | { 10 | //! \brief A quick way to load in various datatypes from an XML config file. 11 | //! Config file should be XML of format: 12 | //! 13 | //! Supports: int/float/string/bool/vector2 14 | //! Stolen from Alec Holowka's code 15 | class ConfigValues 16 | { 17 | public: 18 | ConfigValues(); 19 | static void Load(const std::string &filename); 20 | static std::string GetString(const std::string &valueName); 21 | static int GetInt(const std::string &valueName); 22 | static float GetFloat(const std::string &valueName); 23 | static bool GetBool(const std::string &valueName); 24 | static Vector2 GetVector2(const std::string &valueName); 25 | 26 | private: 27 | static ConfigValues *instance; 28 | 29 | std::map ints; 30 | std::map floats; 31 | std::map strings; 32 | std::map bools; 33 | std::map vector2s; 34 | }; 35 | 36 | } -------------------------------------------------------------------------------- /Core/Debug.cpp: -------------------------------------------------------------------------------- 1 | #include "Debug.h" 2 | 3 | #include 4 | #include "Entity.h" 5 | 6 | namespace Monocle 7 | { 8 | bool Debug::render = false; 9 | bool Debug::showBounds = false; 10 | Entity *Debug::selectedEntity; 11 | int Debug::layerMin = -50; 12 | int Debug::layerMax = 50; 13 | 14 | void Debug::Init() 15 | { 16 | render = false; 17 | } 18 | 19 | void Debug::Log(const char *outputString) 20 | { 21 | // poop stuff out to a file! 22 | //outputString 23 | 24 | std::cout << outputString << std::endl; 25 | } 26 | 27 | void Debug::Log(bool boolean) 28 | { 29 | std::cout << (boolean?"true":"false") << std::endl; 30 | } 31 | 32 | void Debug::Log(int num) 33 | { 34 | std::cout << num << std::endl; 35 | } 36 | 37 | void Debug::Log(long num) 38 | { 39 | std::cout << num << std::endl; 40 | } 41 | 42 | void Debug::Log(float num) 43 | { 44 | std::cout << num << std::endl; 45 | } 46 | 47 | void Debug::Log(double num) 48 | { 49 | std::cout << num << std::endl; 50 | } 51 | 52 | void Debug::Log(const Vector2& vec) 53 | { 54 | std::cout << "Vector2: (" << vec.x << ", " << vec.y << ")" << std::endl; 55 | } 56 | 57 | void Debug::Log(const Vector3& vec) 58 | { 59 | std::cout << "Vector3: (" << vec.x << ", " << vec.y << ", " << vec.z << ")" << std::endl; 60 | } 61 | 62 | void Debug::Log(const std::string& string) 63 | { 64 | std::cout << string << std::endl; 65 | } 66 | } -------------------------------------------------------------------------------- /Core/Debug.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "Vector2.h" 4 | #include "Vector3.h" 5 | #include 6 | 7 | namespace Monocle 8 | { 9 | class Entity; 10 | 11 | //! 12 | //! \brief Holds debug log functions, stores data that controls debug output throughout Monocle 13 | //! 14 | class Debug 15 | { 16 | public: 17 | void Init(); 18 | static void Log(const char *string); 19 | static void Log(bool boolean); 20 | static void Log(int num); 21 | static void Log(long num); 22 | static void Log(float num); 23 | static void Log(double num); 24 | static void Log(const Vector2& vec); 25 | static void Log(const Vector3& vec); 26 | static void Log(const std::string& string); 27 | 28 | static bool render; 29 | static bool showBounds; 30 | 31 | //! used by LevelEditor and PuppetEditor, as well as Entity for rendering selection effects 32 | static Entity *selectedEntity; 33 | 34 | //! Entities in layers outside of this range won't be subject to Debug::render or Debug::showBounds 35 | static int layerMin; 36 | static int layerMax; 37 | }; 38 | } -------------------------------------------------------------------------------- /Core/Editor.cpp: -------------------------------------------------------------------------------- 1 | #include "Editor.h" 2 | #include "Input.h" 3 | #include "Scene.h" 4 | #include "Entity.h" 5 | #include "MonocleToolkit.h" 6 | #include 7 | 8 | namespace Monocle 9 | { 10 | 11 | Editor::Editor() : Entity() 12 | { 13 | // set layer on top of foreground selectable layer (i.e. avoid having this entity be considered for selection) 14 | SetLayer(Debug::layerMin - 1); 15 | } 16 | 17 | // update the camera controls 18 | void CameraEditor::UpdateCamera() 19 | { 20 | if (!Input::IsKeyHeld(KEY_LCTRL)) 21 | { 22 | float moveSpeed = 200.0f; 23 | float zoomSpeed = 0.5f; 24 | 25 | if (Input::IsKeyHeld(KEY_LSHIFT)) 26 | { 27 | moveSpeed *= 5.0f; 28 | zoomSpeed *= 2.0f; 29 | } 30 | 31 | Camera *mainCamera = Scene::GetMainCamera(); 32 | 33 | if (Platform::mouseScroll != 0) 34 | { 35 | const float minZoom = 0.01f; 36 | mainCamera->scale += (Platform::mouseScroll * Vector2::one * 0.00025f); 37 | if (mainCamera->scale.x < minZoom) 38 | { 39 | mainCamera->scale = Vector2::one * minZoom; 40 | } 41 | Vector2 camZoom = mainCamera->scale; 42 | printf("camZoom (%f, %f)\n", camZoom.x, camZoom.y); 43 | } 44 | 45 | if (Input::IsMouseButtonPressed(MOUSE_BUTTON_MIDDLE)) 46 | { 47 | lastWorldMousePosition = Input::GetWorldMousePosition(); 48 | } 49 | 50 | if (Input::IsMouseButtonHeld(MOUSE_BUTTON_MIDDLE)) 51 | { 52 | Vector2 diff = Input::GetWorldMousePosition() - lastWorldMousePosition; 53 | mainCamera->position += (-1*diff); 54 | lastWorldMousePosition = Input::GetWorldMousePosition(); 55 | 56 | Vector2 camPos = mainCamera->position; 57 | printf("camPos (%d, %d)\n", (int)camPos.x, (int)camPos.y); 58 | } 59 | 60 | Vector2 moveDiff = (Input::IsKeyHeld(KEY_KP4) ? Vector2::left : Vector2::zero) + (Input::IsKeyHeld(KEY_KP6) ? Vector2::right : Vector2::zero); 61 | moveDiff += (Input::IsKeyHeld(KEY_KP8) ? Vector2::up : Vector2::zero) + (Input::IsKeyHeld(KEY_KP5) ? Vector2::down : Vector2::zero); 62 | 63 | const float cameraMoveSpeed = 800.0f; // replace with virtualWidth 64 | moveDiff *= Monocle::deltaTime * cameraMoveSpeed; 65 | mainCamera->position += moveDiff; 66 | 67 | float zoomDiff = (Input::IsKeyHeld(KEY_KP7) ? -1.0f : 0.0f) + (Input::IsKeyHeld(KEY_KP9) ? 1.0f : 0.0f); 68 | const float cameraZoomSpeed = 1.0f; 69 | mainCamera->scale += zoomDiff * cameraZoomSpeed * Vector2::one * Monocle::deltaTime; 70 | } 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /Core/Editor.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "Vector2.h" 4 | #include "Entity.h" 5 | 6 | namespace Monocle 7 | { 8 | //! Base class for Editors. 9 | class Editor : public Entity 10 | { 11 | public: 12 | Editor(); 13 | virtual ~Editor() {} 14 | }; 15 | 16 | //! Additional base class for editors that require the ability to change camera position 17 | class CameraEditor 18 | { 19 | public: 20 | virtual ~CameraEditor() {} 21 | protected: 22 | //! Updates zoom (mousewheel) and position(middle click) of camera 23 | void UpdateCamera(); 24 | Vector2 lastWorldMousePosition; 25 | }; 26 | } 27 | -------------------------------------------------------------------------------- /Core/FileNode.cpp: -------------------------------------------------------------------------------- 1 | #include "FileNode.h" -------------------------------------------------------------------------------- /Core/FileNode.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | namespace Monocle 6 | { 7 | class Vector2; 8 | class Color; 9 | class Entity; 10 | 11 | class FileNode 12 | { 13 | public: 14 | virtual void Write(const std::string &name, const int &value)=0; 15 | virtual void Write(const std::string &name, const float &value)=0; 16 | virtual void Write(const std::string &name, const std::string &value)=0; 17 | virtual void Write(const std::string &name, const Vector2 &value)=0; 18 | virtual void Write(const std::string &name, const Color &value)=0; 19 | virtual void Write(const std::string &name, const bool &value)=0; 20 | 21 | virtual void Read(const std::string &name, int &value)=0; 22 | virtual void Read(const std::string &name, float &value)=0; 23 | virtual void Read(const std::string &name, std::string &value)=0; 24 | virtual void Read(const std::string &name, Vector2 &value)=0; 25 | virtual void Read(const std::string &name, Color &value)=0; 26 | virtual void Read(const std::string &name, bool &value)=0; 27 | 28 | virtual FileNode* FirstChildNode(const std::string &name)=0; 29 | virtual FileNode* NextChildNode(const std::string &name)=0; 30 | 31 | virtual void SaveChildNode(const std::string &name, Entity *entity)=0; 32 | //virtual FileNode* NewNode(const std::string &name)=0; 33 | //virtual FileNode* InsertEndChildNode(const std::string &name)=0; 34 | }; 35 | } 36 | -------------------------------------------------------------------------------- /Core/FontAsset.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "Asset.h" 4 | #include "Rect.h" 5 | 6 | namespace Monocle 7 | { 8 | //! \brief An base class for assets encapsulating fonts. 9 | //! Classes inheriting FontAsset should provide a Load function taking the parameters necessary for 10 | //! initialization in addition to the required abstract functions. 11 | class FontAsset : public Asset 12 | { 13 | public: 14 | FontAsset(): Asset(ASSET_FONT) {} 15 | 16 | //! Determines the bounds of a character. 17 | //! \param c [in] The character to compute bounds for 18 | //! \param x [in,out] The x location that this character will be rendered at 19 | //! \param y [in,out] The y location that this character will be rendered at 20 | //! \param verts [out] The rectangle specifying the bounds of the character 21 | //! \param texCoords [out] The rectangle specifying the texture coordinates used to render the character 22 | //! \remark GetGlyphData may be used to determine how to manually render individual characters. 23 | //! The x and y coordinates passed to the function determine the location of the baseline of the text (equivalent to 24 | //! the lines on a sheet of line paper, where the tails of y's and p's hang below the baseline). Both x and 25 | //! y parameters will be suitable for re-passing to another GetGlyphData call as they will be set to the position 26 | //! at which the character following the current character should be rendered (including a small offset if padding 27 | //! is required). This means GetGlyphData in a loop 28 | //! with non-local x and y variables can be used to compute the bounds of full strings 29 | virtual void GetGlyphData(char c, float* x, float* y, Rect& verts, Rect& texCoords) const = 0; 30 | //! Determines the width a string of text occupies if rendered. 31 | //! \param text [in] The string to compute bounds for 32 | //! \remark This function should not render text. A font asset should have the ability to measure a string by 33 | //! computing the character bounds in memory. 34 | virtual float GetTextWidth(const std::string &text) = 0; 35 | //! Determines the height a string of text occupies if rendered. This function measures height from the top of 36 | //! the highest character to the bottom of the character that spans the lowest. For example, if given the string 37 | //! "The lazy fox," it should return the height from the top of the 'T' to the bottom of the 'y.' 38 | //! \param text [in] The string to compute bounds for 39 | //! \remark This function should not render text. A font asset should have the ability to measure a string by 40 | //! computing the character bounds in memory. 41 | //! Special attention should be paid if you need strict metrics for font positioning. This function does not 42 | //! return the height from the baseline, so basing the rendering position on output from this function (ie 43 | //! rendering text at GetTextHeight()/2 to attempt to center the baseline) will cause the baseline position 44 | //! to fluctuate between strings like "flies" and "fly" when the y changes the overall string height. 45 | virtual float GetTextHeight(const std::string &text) = 0; 46 | 47 | unsigned int texID; 48 | }; 49 | } -------------------------------------------------------------------------------- /Core/GUI.cpp: -------------------------------------------------------------------------------- 1 | #include "GUI.h" 2 | 3 | namespace TestGUI 4 | { 5 | 6 | } -------------------------------------------------------------------------------- /Core/GUI.h: -------------------------------------------------------------------------------- 1 | #include "Entity.h" 2 | 3 | // in TestGUI namespace until code is written + refactored 4 | namespace TestGUI 5 | { 6 | } -------------------------------------------------------------------------------- /Core/Game.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "Monocle.h" 4 | #include "Input.h" 5 | #include "Graphics.h" 6 | #include "Debug.h" 7 | #include "Scene.h" 8 | #include "Assets.h" 9 | #include "Tween.h" 10 | #include "Collision.h" 11 | #include "Random.h" 12 | #include "Audio/Audio.h" 13 | #include "Level.h" 14 | 15 | namespace Monocle 16 | { 17 | 18 | //! Base class for creating a new game. Manages the main loop, timer and high-level updating, rendering. 19 | //! Some games will be able to get away with just instantiating this class and adding Scenes. 20 | //! Some developers may want to extend Game and customize it, instead. 21 | class Game 22 | { 23 | public: 24 | //! Initializes all the default sub-systems. Platform, Input, Graphics, Debug, Assets, Tween, Collision, Random, Audio, Level 25 | Game(const std::string &name="MonoclePowered.org", int w=1024, int h=768, int bits = MONOCLE_DETECT_COLOR_DEPTH, bool fullscreen=false); 26 | 27 | //! Runs the main game loop. Handles timing and high-level updating, rendering. 28 | void Main(); 29 | 30 | //! Updates the game state. Derived classes may override this to provide extra functionality that must be 31 | //! executed in each game loop iteration. 32 | virtual void Update(); 33 | 34 | //! Sets the current Scene. Games can run one Scene at a time. 35 | static void SetScene(Scene* scene); 36 | //! Returns a pointer to the currently running Scene. 37 | static Scene* GetScene(); 38 | 39 | //! Call Game::Quit to quit the main loop. (exit your game) 40 | static void Quit(); 41 | 42 | //! Receives a string-based message, referred to as a "note." Can be overloaded. 43 | //virtual void ReceiveNote(const std::string ¬e); 44 | 45 | //virtual void Init(); 46 | static float frames_per_sec; 47 | 48 | private: 49 | static Game *instance; 50 | 51 | //! Notifies the Game if it needs to exit sanely at the next opportunity 52 | bool isDone; 53 | 54 | //! The scene that is currently running 55 | Scene* scene; 56 | 57 | //! Scene to switch to at the end of the frame; if NULL, no switch 58 | Scene* switchTo; 59 | 60 | Platform platform; 61 | Input input; 62 | Graphics graphics; 63 | Debug debug; 64 | Assets assets; 65 | Tween tween; 66 | Collision collision; 67 | Random random; 68 | Audio audio; 69 | Level level; 70 | }; 71 | } 72 | -------------------------------------------------------------------------------- /Core/Graphics/Sprite.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "../Color.h" 4 | #include "../TextureAsset.h" 5 | #include "../Graphics.h" 6 | #include 7 | 8 | namespace Monocle 9 | { 10 | class Entity; 11 | 12 | class Sprite : public Graphic 13 | { 14 | public: 15 | Sprite(const std::string &filename, float width=-1, float height=-1); 16 | Sprite(const std::string &filename, FilterType filter, float width=-1, float height=-1); 17 | Sprite(); 18 | ~Sprite(); 19 | //void Update(); 20 | void Render(Entity *entity); 21 | void GetWidthHeight(int *width, int *height); 22 | 23 | TextureAsset *texture; 24 | float width, height;//,angle; 25 | Vector2 textureOffset; 26 | Vector2 textureScale; 27 | 28 | BlendType blend; 29 | }; 30 | } -------------------------------------------------------------------------------- /Core/Graphics/SpriteAnimation.cpp: -------------------------------------------------------------------------------- 1 | #include "SpriteAnimation.h" 2 | #include "Sprite.h" 3 | #include "../MonocleToolkit.h" 4 | #include "../Debug.h" 5 | 6 | namespace Monocle 7 | { 8 | 9 | Anim::Anim(const std::string &name, int start, int end, float speed) 10 | : name(name), start(start), end(end), speed(speed), frame(start), isPlaying(false) 11 | { 12 | 13 | } 14 | 15 | SpriteAnimation::SpriteAnimation(const std::string &filename, FilterType filter, float width, float height) 16 | : Sprite(filename, filter, width, height) 17 | { 18 | 19 | } 20 | 21 | void SpriteAnimation::Add(const std::string &name, int start, int end, float speed) 22 | { 23 | Anim a = Anim(name, start, end, speed); 24 | animations.push_back(a); 25 | } 26 | 27 | void SpriteAnimation::Play(const std::string &name) 28 | { 29 | animation = GetAnim(name); 30 | if (animation) 31 | { 32 | animation->isPlaying = true; 33 | } 34 | 35 | } 36 | 37 | void SpriteAnimation::Stop(const std::string &name) 38 | { 39 | animation = GetAnim(name); 40 | if (animation) 41 | { 42 | animation->isPlaying = false; 43 | } 44 | } 45 | 46 | void SpriteAnimation::Render(Entity *entity) 47 | { 48 | int x = 0; 49 | int y = 0; 50 | 51 | if(animation) 52 | { 53 | if(animation->isPlaying) 54 | { 55 | animation->frame += animation->speed * Monocle::deltaTime; 56 | if(animation->frame > animation->end + 1) { animation->frame = animation->start; } 57 | } 58 | 59 | x = (int) animation->frame % (int) (texture->width / width); 60 | y = (int) animation->frame / (texture->width / width); 61 | } 62 | 63 | textureOffset = Vector2((x * width) / texture->width, (y * height) / texture->height); 64 | textureScale = Vector2(width / texture->width, height / texture->height); 65 | 66 | Sprite::Render(entity); 67 | } 68 | 69 | Anim* SpriteAnimation::GetAnim(const std::string &name) 70 | { 71 | for (std::list::iterator i = animations.begin(); i != animations.end(); ++i) 72 | { 73 | if(i->name == name) 74 | { 75 | return &(*i); 76 | } 77 | } 78 | Debug::Log("Warning: Could not find animation named: " + name); 79 | return NULL; 80 | } 81 | 82 | 83 | } -------------------------------------------------------------------------------- /Core/Graphics/SpriteAnimation.h: -------------------------------------------------------------------------------- 1 | #include "Sprite.h" 2 | #include 3 | 4 | #pragma once 5 | 6 | namespace Monocle 7 | { 8 | 9 | class Anim 10 | { 11 | public: 12 | Anim(const std::string &name, int start, int end, float speed); 13 | Anim(); 14 | bool isPlaying; 15 | const std::string name; 16 | float frame; 17 | float speed; 18 | int start; 19 | int end; 20 | }; 21 | 22 | class SpriteAnimation : public Sprite 23 | { 24 | public: 25 | SpriteAnimation(const std::string &filename, FilterType filter, float width, float height); 26 | void Add(const std::string &name, int start, int end, float speed); 27 | void Play(const std::string &name); 28 | void Stop(const std::string &name); 29 | Anim* GetAnim(const std::string &name); 30 | void Render(Entity *entity); 31 | 32 | std::list animations; 33 | Anim* animation; 34 | }; 35 | } -------------------------------------------------------------------------------- /Core/Graphics/Tilemap.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "../Graphics.h" 4 | #include "../Tileset.h" 5 | #include "../TextureAsset.h" 6 | #include "../Vector2.h" 7 | #include 8 | 9 | namespace Monocle 10 | { 11 | class Level; 12 | 13 | class Tilemap : public Graphic 14 | { 15 | public: 16 | Tilemap(Tileset *tileset, int width, int height, int tileWidth, int tileHeight); 17 | 18 | void Resize(int width, int height); 19 | 20 | void GetWidthHeight(int *width, int *height); 21 | 22 | bool IsTile(int tx, int ty, int tileID); 23 | int GetTile(int tx, int ty); 24 | void SetTile(int tx, int ty, int tileID); 25 | 26 | int GetTileAtWorldPosition(const Vector2 &position); 27 | void SetTileAtWorldPosition(const Vector2 &position, int tileID); 28 | 29 | void WorldToTile(const Vector2 &position, int *tx, int *ty); 30 | 31 | void Render(Entity *entity); 32 | 33 | void Clear(int tileID=-1); 34 | 35 | TextureAsset *texture; 36 | 37 | private: 38 | friend class Level; 39 | Tileset *tileset; 40 | int width, height; 41 | int tileWidth, tileHeight; 42 | std::vector tiles; 43 | 44 | void UpdateEditor(); 45 | 46 | static int selectedTile; 47 | }; 48 | } -------------------------------------------------------------------------------- /Core/LevelEditor/FringeTile.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "../Graphics/Sprite.h" 4 | #include "../Entity.h" 5 | #include "../Asset.h" 6 | #include 7 | #include 8 | 9 | namespace Monocle 10 | { 11 | class FringeTileData 12 | { 13 | public: 14 | FringeTileData() 15 | : width(-1), height(-1), repeatX(false), repeatY(false), autoTile(false) 16 | {} 17 | 18 | FringeTileData(const std::string &imageFilename, int width=-1, int height=-1, FilterType filter=FILTER_LINEAR, bool repeatX=false, bool repeatY=false, int atlasX=0, int atlasY=0, int atlasW=0, int atlasH=0, bool autoTile = false) 19 | : imageFilename(imageFilename), repeatX(repeatX), repeatY(repeatY), filter(filter), width(width), height(height), atlasX(atlasX), atlasY(atlasY), atlasW(atlasW), atlasH(atlasH), autoTile(autoTile) 20 | {} 21 | 22 | std::string imageFilename; 23 | int width, height; 24 | FilterType filter; 25 | bool repeatX, repeatY; 26 | int atlasX, atlasY, atlasW, atlasH; 27 | bool autoTile; 28 | // bool useFiltering; 29 | }; 30 | 31 | class FringeTileset 32 | { 33 | public: 34 | FringeTileset(const std::string &name); 35 | ~FringeTileset(); 36 | 37 | bool IsName(const std::string &name); 38 | const std::string &GetName(); 39 | 40 | const FringeTileData *GetFringeTileDataByID(int tileID); 41 | void SetFringeTileData(int tileID, FringeTileData *fringeTileData); 42 | int GetNextTileID(int tileID); 43 | int GetPrevTileID(int tileID); 44 | 45 | 46 | private: 47 | int maxTileID; 48 | std::string name; 49 | std::map fringeTileData; 50 | }; 51 | 52 | class FringeTile : public Entity 53 | { 54 | public: 55 | FringeTile(); 56 | FringeTile(const FringeTile &fringeTile); 57 | Entity *Clone(); 58 | //FringeTile(FringeTileset *fringeTileset, int tileID); 59 | void SetTileID(int tileID); 60 | int GetTileID(); 61 | void PrevTile(); 62 | void NextTile(); 63 | void PrevBlend(); 64 | void NextBlend(); 65 | void Update(); 66 | //FringeTileset *GetFringeTileset(); 67 | Sprite *sprite; 68 | 69 | void Save(FileNode *fileNode); 70 | void Load(FileNode *fileNode); 71 | 72 | private: 73 | void RefreshTexture(); 74 | void RefreshScale(); 75 | int tileID; 76 | //FringeTileset *fringeTileset; 77 | }; 78 | } -------------------------------------------------------------------------------- /Core/LevelEditor/ImageBrowser.cpp: -------------------------------------------------------------------------------- 1 | #include "ImageBrowser.h" 2 | #include "../Input.h" 3 | #include "../MonocleToolkit.h" 4 | #include "../Graphics/Sprite.h" 5 | #include "../Game.h" 6 | 7 | namespace Monocle 8 | { 9 | SelectionImage::SelectionImage(const std::string &image, int size) 10 | : Entity() 11 | { 12 | Sprite *sprite = NULL; 13 | SetGraphic(sprite = new Sprite(image)); 14 | if (sprite->width > sprite->height) 15 | { 16 | sprite->height = (sprite->height/sprite->width) * size; 17 | sprite->width = size; 18 | } 19 | else 20 | { 21 | sprite->width = (sprite->width/sprite->height) * size; 22 | sprite->height = size; 23 | } 24 | } 25 | 26 | void SelectionImage::Update() 27 | { 28 | Entity::Update(); 29 | 30 | Vector2 diff = Input::GetWorldMousePosition() - GetWorldPosition();//position - Graphics::GetScreenCenter(); 31 | float mag = (1.0f-(diff.GetMagnitude()/256.0f)) * 1.0f; 32 | if (mag < 0.5f) mag = 0.5f; 33 | if (mag > 1.25f) mag = 1.25f; 34 | scale = Vector2::one * mag; 35 | printf("scale %f, %f\n", scale.x, scale.y); 36 | } 37 | 38 | /// IMAGE BROWSER 39 | ImageBrowser::ImageBrowser() 40 | : Entity(), selectionImageSize(128), hasContent(false) 41 | { 42 | SetLayer(-85); 43 | followCamera = Vector2::one; 44 | } 45 | 46 | void ImageBrowser::Update() 47 | { 48 | scale = Game::GetScene()->GetCamera()->scale; 49 | scale = Vector2(1/scale.x, 1/scale.y); 50 | 51 | Entity::Update(); 52 | 53 | if (hasContent) 54 | { 55 | for (int key = (int)KEY_A; key <= (int)KEY_Z; key++) 56 | { 57 | if (Input::IsKeyPressed((KeyCode)key)) 58 | { 59 | // select next image with name starting with first letter "key" 60 | // i.e. if key A is pressed selected Aardvark 61 | // if key A is pressed again, select Aardvark2 62 | } 63 | } 64 | 65 | grid->position += Platform::mouseScroll * Vector2::down * 0.25f; 66 | printf("position %f, %f\n", grid->position.x, grid->position.y); 67 | } 68 | } 69 | 70 | void ImageBrowser::ScanDirectory(const std::string &directory) 71 | { 72 | hasContent = false; 73 | //DestroyChildren(); 74 | selectionImages.clear(); 75 | 76 | Entity *bg = new Entity(); 77 | scene->Add(bg); 78 | bg->SetParent(this); 79 | bg->SetGraphic(new Sprite("", 128, 600)); 80 | bg->color = Color::black; 81 | bg->color.a = 0.75f; 82 | 83 | 84 | grid = new Entity(); 85 | scene->Add(grid); 86 | grid->SetParent(this); 87 | 88 | ForEachFile(directory, "png", &ImageBrowser::FileCallback, (intptr_t)this); 89 | } 90 | 91 | void ImageBrowser::FileCallback(const std::string &filename, intptr_t pointer) 92 | { 93 | ImageBrowser *imageBrowser = (ImageBrowser*)pointer; 94 | imageBrowser->NewSelectionImage(filename); 95 | } 96 | 97 | void ImageBrowser::SetImages(const std::vector &images) 98 | { 99 | //DestroyChildren(); 100 | selectionImages.clear(); 101 | 102 | for (int i = 0; i < images.size(); i++) 103 | { 104 | NewSelectionImage(images[i]); 105 | } 106 | } 107 | 108 | void ImageBrowser::NewSelectionImage(const std::string &filename) 109 | { 110 | SelectionImage *selectionImage = new SelectionImage(filename, selectionImageSize); 111 | scene->Add(selectionImage); 112 | selectionImage->SetParent(this); 113 | //grid->Add(selectionImage); 114 | selectionImage->position = Vector2(0.0f, selectionImageSize * selectionImages.size()); 115 | 116 | selectionImages.push_back(selectionImage); 117 | 118 | hasContent = true; 119 | } 120 | } 121 | -------------------------------------------------------------------------------- /Core/LevelEditor/ImageBrowser.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "../Entity.h" 4 | 5 | namespace Monocle 6 | { 7 | class SelectionImage : public Entity 8 | { 9 | public: 10 | SelectionImage(const std::string &image, int size); 11 | void Update(); 12 | }; 13 | 14 | class ImageBrowser : public Entity 15 | { 16 | public: 17 | ImageBrowser(); 18 | void Update(); 19 | //void Render(); 20 | void ScanDirectory(const std::string &directory); 21 | void SetImages(const std::vector &images); 22 | 23 | private: 24 | static void FileCallback(const std::string &filename, intptr_t pointer); 25 | void NewSelectionImage(const std::string &filename); 26 | 27 | int selectionImageSize; 28 | bool hasContent; 29 | std::list selectionImages; 30 | Entity *grid; 31 | }; 32 | } 33 | -------------------------------------------------------------------------------- /Core/LevelEditor/LevelEditor.h: -------------------------------------------------------------------------------- 1 | #include "../Vector2.h" 2 | #include "../Entity.h" 3 | #include "../Input.h" 4 | #include "Node.h" 5 | #include "../Editor.h" 6 | 7 | namespace Monocle 8 | { 9 | class FringeTile; 10 | class Scene; 11 | class Entity; 12 | class ImageBrowser; 13 | 14 | enum FringeTileEditorState 15 | { 16 | FTES_NONE=0, 17 | FTES_MOVE, 18 | FTES_ROTATE, 19 | FTES_SCALE, 20 | FTES_COMMAND, 21 | FTES_BROWSER, 22 | FTES_COLOR, 23 | FTES_FLIP, 24 | FTES_MAX 25 | }; 26 | 27 | /* 28 | class Cursor : public Entity 29 | { 30 | public: 31 | Cursor(); 32 | void Update(); 33 | void Render(); 34 | }; 35 | */ 36 | 37 | class LevelEditor : public Editor, public CameraEditor 38 | { 39 | public: 40 | LevelEditor(); 41 | void Enable(); 42 | void Disable(); 43 | void Update(); 44 | FringeTileEditorState GetState() 45 | { 46 | return state; 47 | } 48 | 49 | protected: 50 | //void UpdateCamera(); 51 | void UpdateSelect(); 52 | void UpdateOpportunity(); 53 | void UpdateMove(); 54 | void UpdateRotate(); 55 | void UpdateScale(); 56 | void UpdateColor(); 57 | void UpdateCommands(); 58 | 59 | void UpdateNumberEntry(); 60 | 61 | void ApplyGrid(Entity *entity, int gridSize); 62 | 63 | void CloneEntity(Entity *entity, const Vector2 &position); 64 | 65 | void SetState(FringeTileEditorState state); 66 | 67 | void Select(Entity *entity); 68 | 69 | Entity *selectedEntity; 70 | 71 | FringeTile *selectedFringeTile; 72 | Node *selectedNode; 73 | ImageBrowser *imageBrowser; 74 | 75 | Vector2 moveOffset; 76 | Vector2 moveStartPosition; 77 | float moveStartMagnitude; 78 | float startRotation; 79 | Vector2 startScale; 80 | Color startColor; 81 | 82 | bool waitForLMBRelease; 83 | 84 | FringeTileEditorState state; 85 | Vector2 lastWorldMousePosition; 86 | //Cursor *cursor; 87 | int moveAxisLock; 88 | int changeColorValue; 89 | 90 | KeyCode keyMove; 91 | KeyCode keyRotate; 92 | KeyCode keyScale; 93 | KeyCode keySelect; 94 | KeyCode keyColor; 95 | KeyCode keyFocus; 96 | KeyCode keyClone; 97 | KeyCode keyFlip; 98 | KeyCode keyFlipH; 99 | KeyCode keyFlipV; 100 | KeyCode keyPrevTile; 101 | KeyCode keyNextTile; 102 | KeyCode keyDelete; 103 | KeyCode keyScaleDown; 104 | KeyCode keyScaleUp; 105 | KeyCode keyOpenImageBrowser; 106 | 107 | bool isNumberEntry; 108 | std::string numberEntryString; 109 | float numberEntryValue; 110 | 111 | std::string text; 112 | 113 | /// NODE 114 | //void CloneNode(); 115 | }; 116 | } 117 | -------------------------------------------------------------------------------- /Core/LevelEditor/Node.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "../Entity.h" 4 | 5 | namespace Monocle 6 | { 7 | //! /brief Linked list marker. Used to describe paths. 8 | class Node : public Entity 9 | { 10 | public: 11 | Node(const Node &node); 12 | Node(); 13 | Node(const Vector2 &position); 14 | Entity* Clone(); 15 | void Update(); 16 | void Render(); 17 | void Disconnect(); 18 | void TakeOut(); 19 | 20 | void SetNext(Node *node); 21 | void InsertNext(Node *node); 22 | 23 | Node *GetNext(); 24 | Node *GetPrev(); 25 | 26 | void Save(FileNode *fileNode); 27 | void Load(FileNode *fileNode); 28 | 29 | int variant; 30 | 31 | 32 | private: 33 | Node *next; 34 | Node *prev; 35 | }; 36 | } 37 | 38 | -------------------------------------------------------------------------------- /Core/LevelEditor/PathMesh.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "../Entity.h" 4 | 5 | namespace Monocle 6 | { 7 | class TextureAsset; 8 | class Node; 9 | class PathCollider; 10 | 11 | class PathMesh : public Entity 12 | { 13 | public: 14 | PathMesh(); 15 | PathMesh(const std::string &textureFilename, int cells, Node *startNode, int size); 16 | void SetStartNode(Node *node); 17 | Node* GetStartNode(); 18 | void Render(); 19 | void Save(FileNode *fileNode); 20 | void Load(FileNode *fileNode); 21 | void MakeCollision(float radius); 22 | 23 | int cells; 24 | bool flipX, flipY; 25 | 26 | private: 27 | //std::list nodes; 28 | TextureAsset *texture; 29 | int size; 30 | Node *startNode; 31 | std::vector nodes; 32 | PathCollider *pathCollider; 33 | }; 34 | } 35 | -------------------------------------------------------------------------------- /Core/Linux/LinuxPlatform.h: -------------------------------------------------------------------------------- 1 | #ifdef MONOCLE_LINUX 2 | 3 | #pragma once 4 | 5 | #include "../Platform.h" 6 | 7 | #include 8 | #include 9 | 10 | namespace Monocle 11 | { 12 | class LinuxPlatform 13 | { 14 | public: 15 | 16 | Display *hDisplay; 17 | int hScreen; 18 | Window hWindow; 19 | GLXContext GC; 20 | 21 | bool active; // Window Active Flag Set To TRUE By Default 22 | bool fullscreen; // Fullscreen Flag Set To Fullscreen Mode By Default 23 | 24 | static LinuxPlatform* instance; 25 | Platform *platform; 26 | 27 | LinuxPlatform() 28 | : hDisplay(NULL), 29 | hScreen(NULL), 30 | hWindow(NULL), 31 | GC(NULL) 32 | { 33 | active = true; 34 | fullscreen = true; 35 | instance = this; 36 | } 37 | 38 | bool CreatePlatformWindow(const char* title, int width, int height, int bits, bool fullscreenflag); 39 | void KillPlatformWindow(); 40 | void CenterWindow(); 41 | static void GetDesktopSize(int *width, int *height); 42 | }; 43 | 44 | } 45 | #endif 46 | -------------------------------------------------------------------------------- /Core/Macros.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | /* MIN and MAX 4 | Standard math min/max macros. 5 | MIN returns the smaller of the arguments. 6 | MAX returns the larger of the arguments. 7 | */ 8 | #define MIN(a, b) (((a) < (b)) ? (a) : (b)) 9 | #define MAX(a, b) (((a) > (b)) ? (a) : (b)) 10 | 11 | /* CLAMP 12 | Combines min and max in one macro for convenience. 13 | */ 14 | #define CLAMP(a, min, max) MIN(MAX(a, max), min) 15 | 16 | /* SIGN 17 | If value is larger than 0, return to. 18 | If value is smaller than 0, return -to. 19 | If value is 0, return 0. 20 | */ 21 | #define SIGN(value, to) ((value < 0) ? -to : ((value > 0) ? to : 0)) 22 | 23 | /* SIGN 24 | If value is positive or zero, return 1 25 | If negative return -1 26 | */ 27 | #define SIGNOF(value) ((value >= 0) ? 1 : -1) 28 | 29 | /* APPROACH 30 | Returns value shifted toward target by amount, without crossing target. 31 | For example, APPROACH(2, 0, 3) will perform 2 - 3 = -1, but return 0 because -1 crossed the target of 0. 32 | APPROACH(-4, 0, 3) will return -1, because it will perform -4 + 3 = -1. 33 | */ 34 | #define APPROACH(value, target, amount) ((value >= target) ? MAX(value - amount, target) : MIN(value + amount, target)) 35 | 36 | /* LERP 37 | Linearly interpolate between two values. 38 | For example LERP(0, 10, 0.5) = 5, because 5 is 50% between 0 and 10. 39 | LERP(0, -4, 0.75) = -3, because -3 is 75% between 0 and -4. 40 | */ 41 | #define LERP(a, b, t) (a + (b - a) * t) 42 | 43 | #define WEIGHTED_AVERAGE(current, target, slowdown) ((current * (slowdown - 1)) + target) / slowdown -------------------------------------------------------------------------------- /Core/Monocle.cpp: -------------------------------------------------------------------------------- 1 | #include "Monocle.h" 2 | 3 | 4 | -------------------------------------------------------------------------------- /Core/Monocle.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "Game.h" 4 | #include "MonocleToolkit.h" 5 | 6 | /*! \mainpage Monocle Engine 7 | * 8 | * \section intro_sec Introduction 9 | * 10 | * This is the Monocle Engine introduction. 11 | * 12 | * \section start_sec Getting Started 13 | * 14 | * \subsection step1 Step 1: Do Something... 15 | * 16 | * etc... 17 | */ -------------------------------------------------------------------------------- /Core/MonocleToolkit.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "Macros.h" 4 | #include 5 | #include 6 | 7 | namespace Monocle 8 | { 9 | //! Time in seconds that has passed since the last frame 10 | extern double deltaTime; 11 | 12 | //! Time in seconds since game started 13 | extern double timeSinceStart; 14 | 15 | //! Time in seconds since current scene started 16 | extern double timeSinceSceneStart; 17 | 18 | //! Math symbol PI 19 | extern const float pi; 20 | 21 | //! Convert radians to degrees 22 | extern const float rad2Deg; 23 | 24 | //! Convert degrees to radians 25 | extern const float deg2Rad; 26 | 27 | //! Open a local file or remote URL 28 | void OpenURL(const std::string &url); 29 | //! return the current working directory 30 | std::string GetWorkingDirectory(); 31 | //! call a callback function for each file in the directory with file extension equal to type 32 | void ForEachFile(std::string path, std::string type, void callback(const std::string &filename, intptr_t param), intptr_t param); 33 | 34 | template 35 | std::string StringOf(T object) 36 | { 37 | std::ostringstream os; 38 | os << object; 39 | return(os.str()); 40 | }; 41 | } 42 | -------------------------------------------------------------------------------- /Core/Puppet/PuppetEditor.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "../Editor.h" 4 | #include "../Input.h" 5 | #include "Puppet.h" 6 | 7 | namespace Monocle 8 | { 9 | class Timeline : public Entity 10 | { 11 | public: 12 | Timeline(); 13 | Animation *currentAnimation; 14 | void Render(); 15 | }; 16 | 17 | class PuppetEntity : public Entity 18 | { 19 | public: 20 | PuppetEntity(); 21 | void Load(const std::string &filename); 22 | void Update(); 23 | 24 | Puppet puppet; 25 | }; 26 | 27 | class PuppetEditor : public Editor, public CameraEditor 28 | { 29 | public: 30 | PuppetEditor(); 31 | void Load(const std::string &filename); 32 | void Enable(); 33 | void Disable(); 34 | void Update(); 35 | void Added(); 36 | 37 | KeyCode keyTogglePause; 38 | 39 | KeyCode keyMoveLeft; 40 | KeyCode keyMoveRight; 41 | KeyCode keyMoveUp; 42 | KeyCode keyMoveDown; 43 | 44 | KeyCode keyRotateLeft; 45 | KeyCode keyRotateRight; 46 | 47 | KeyCode keyBackwards; 48 | KeyCode keyForwards; 49 | 50 | KeyCode keySetKeyFrame; 51 | 52 | KeyCode keyZero; 53 | 54 | KeyCode keyOffset; 55 | 56 | Timeline *timeline; 57 | 58 | private: 59 | PuppetEntity *puppetEntity; 60 | }; 61 | 62 | } 63 | -------------------------------------------------------------------------------- /Core/Random.cpp: -------------------------------------------------------------------------------- 1 | #include "Random.h" 2 | #include 3 | #include 4 | 5 | namespace Monocle 6 | { 7 | Random::Random() 8 | { 9 | srand(static_cast(time(NULL))); 10 | } 11 | 12 | void Random::Seed(unsigned int seed) 13 | { 14 | srand(seed); 15 | } 16 | 17 | int Random::Int(int start, int end) 18 | { 19 | return start + (rand() % (end-start)); 20 | } 21 | 22 | float Random::Float(float start, float end) 23 | { 24 | return ((((float) rand()) / (float) RAND_MAX) * (end-start)) + start; 25 | } 26 | 27 | float Random::Percent() 28 | { 29 | return ((float) rand()) / (float) RAND_MAX; 30 | } 31 | 32 | 33 | } -------------------------------------------------------------------------------- /Core/Random.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | namespace Monocle 4 | { 5 | class Random 6 | { 7 | public: 8 | Random(); 9 | static void Seed(unsigned int seed); 10 | //! not inclusive 11 | static int Int(int start, int end); 12 | static float Float(float start, float end); 13 | static float Percent(); 14 | 15 | private: 16 | //static Random *instance; 17 | }; 18 | } -------------------------------------------------------------------------------- /Core/Rect.cpp: -------------------------------------------------------------------------------- 1 | #include "Rect.h" 2 | 3 | namespace Monocle 4 | { 5 | Rect::Rect() 6 | { 7 | } 8 | 9 | Rect::Rect(const Vector2& topLeft, const Vector2& bottomRight): 10 | topLeft(topLeft), bottomRight(bottomRight) 11 | { 12 | 13 | } 14 | 15 | Rect::Rect(const Rect& other): 16 | topLeft(other.topLeft), bottomRight(other.bottomRight) 17 | { 18 | 19 | } 20 | } -------------------------------------------------------------------------------- /Core/Rect.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "Vector2.h" 4 | 5 | 6 | namespace Monocle 7 | { 8 | //! 9 | //! \brief Describes a rectangle. 10 | //! 11 | class Rect 12 | { 13 | public: 14 | Vector2 topLeft, bottomRight; 15 | 16 | Rect(); 17 | Rect(const Vector2& topLeft, const Vector2& bottomRight); 18 | Rect(const Rect& other); 19 | }; 20 | } -------------------------------------------------------------------------------- /Core/TTFFontAsset.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "FontAsset.h" 4 | 5 | namespace Monocle 6 | { 7 | class TTFFontAsset: public FontAsset 8 | { 9 | public: 10 | TTFFontAsset(); 11 | ~TTFFontAsset(); 12 | 13 | bool Load(const std::string &filename, float size, int textureWidth=-1, int textureHeight=-1); 14 | 15 | void Reload(); 16 | void Unload(); 17 | 18 | void GetGlyphData(char c, float* x, float* y, Rect& verts, Rect& texCoords) const; 19 | float GetTextWidth(const std::string &text); 20 | float GetTextHeight(const std::string &text); 21 | //float GetTextWidth(const std::string &text); 22 | 23 | protected: 24 | void* fontCData; 25 | float size; 26 | int textureWidth, textureHeight; 27 | }; 28 | } 29 | -------------------------------------------------------------------------------- /Core/TextureAsset.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "Asset.h" 4 | 5 | namespace Monocle 6 | { 7 | class Vector2; 8 | 9 | class TextureAsset : public Asset 10 | { 11 | public: 12 | TextureAsset(); 13 | //! \brief Loads a texture from a pointer. 14 | //! \param data [in] A pointer to the data to load into the texture. May be null, and if so, a buffer large enough to fit a w*h image is allocated and may 15 | //! be filled at a later time using UpdateRect 16 | //! \param w [in] The width of the image to load 17 | //! \param h [in] The height of the image to load 18 | //! \param filter [in] The type of filter to use on the image 19 | //! \param repeatX [in] Whether or not the texture should be repeated on the x axis if necessary when rendered 20 | //! \param repeatY [in] Whether or not the texture should be repeated on the y axis if necessary when rendered 21 | void Load(const unsigned char* data, int w, int h, FilterType filter, bool repeatX, bool repeatY); 22 | //! \brief Loads a texture from a file 23 | //! \return Whether the load was successful. If this is false, the texture is invalid and should not be used except to attempt another Load 24 | //! \param filename [in] The filename to load from, relative to the current ContentPath 25 | //! \param filter [in] The filter to use on the texture. 26 | //! \param repeatX [in] Whether or not the texture should be repeated on the x axis if necessary when rendered 27 | //! \param repeatY [in] Whether or not the texture should be repeated on the y axis if necessary when rendered 28 | //! \sa Assets::GetContentPath 29 | bool Load(const std::string &filename, FilterType filter, bool repeatX, bool repeatY); 30 | //! \brief Replaces the pixels in a rectangular area of the texture using the data pointed to. 31 | //! \param data [in] The pointer to the data to fill the rectangle with 32 | //! \param position [in] The top left hand corner of the rect to update 33 | //! \param size [in] The size of the rect to update 34 | void UpdateRect(const unsigned char *data, Monocle::Vector2 position, Monocle::Vector2 size); 35 | //! \brief Copies a portion of the texture into another area of the same texture. 36 | //! \param srcPos [in] The top left corner of the rect to copy from 37 | //! \param dstPos [in] The top left corner of the rect to copy to 38 | //! \param size [in] The size of the rect to copy 39 | //! \remarks This function produces a 1:1 scale copy. 40 | void CopyRect(Monocle::Vector2 srcPos, Monocle::Vector2 dstPos, Monocle::Vector2 copysize); 41 | //! \brief Copies a portion of the texture into a buffer, and returns it. 42 | unsigned char *ReadRect(Monocle::Vector2 srcPos, Monocle::Vector2 size); 43 | //! \brief Reloads the texture 44 | void Reload(); 45 | //! \brief Unloads the texture 46 | void Unload(); 47 | 48 | //should have getter functions and be private 49 | unsigned int width, height; 50 | unsigned int texID; 51 | bool repeatX, repeatY; 52 | 53 | private: 54 | FilterType filter; 55 | 56 | }; 57 | } 58 | 59 | -------------------------------------------------------------------------------- /Core/TextureAtlas.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "FileNode.h" 4 | #include "Vector2.h" 5 | 6 | #include 7 | 8 | class TiXmlDocument; 9 | class TiXmlElement; 10 | 11 | namespace Monocle 12 | { 13 | class TextureAtlas; 14 | 15 | class TextureAtlasEntry 16 | { 17 | public: 18 | TextureAtlasEntry(); 19 | TextureAtlasEntry(TextureAtlas *textureAtlas); 20 | void Save(FileNode *fileNode); 21 | void Load(FileNode *fileNode); 22 | 23 | Vector2 GetTextureOffset(); 24 | Vector2 GetTextureScale(); 25 | int GetWidth(); 26 | int GetHeight(); 27 | 28 | private: 29 | friend class TextureAtlas; 30 | std::string name; 31 | int x, y, width, height; 32 | TextureAtlas *textureAtlas; 33 | }; 34 | 35 | class TextureAtlas 36 | { 37 | public: 38 | TextureAtlas(); 39 | ~TextureAtlas(); 40 | TextureAtlasEntry* GetEntryByName(const std::string &name); 41 | void Save(TiXmlDocument *document); 42 | void Load(TiXmlElement *element); 43 | std::string GetImageName(); 44 | 45 | private: 46 | friend class TextureAtlasEntry; 47 | std::string image; 48 | int width, height; 49 | float scale; 50 | 51 | private: 52 | std::map entries; 53 | }; 54 | } 55 | -------------------------------------------------------------------------------- /Core/Tileset.cpp: -------------------------------------------------------------------------------- 1 | #include "Tileset.h" 2 | #include "Assets.h" 3 | 4 | namespace Monocle 5 | { 6 | Tileset::Tileset(const std::string &name, const std::string &filename, float tileWidth, float tileHeight) 7 | : texture(NULL), tileWidth(tileWidth), tileHeight(tileHeight), name(name) 8 | { 9 | texture = Assets::RequestTexture(filename, FILTER_NONE); 10 | } 11 | } -------------------------------------------------------------------------------- /Core/Tileset.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include "TextureAsset.h" 5 | 6 | namespace Monocle 7 | { 8 | class Tileset 9 | { 10 | public: 11 | Tileset(const std::string &name, const std::string &filename, float tileWidth, float tileHeight); 12 | 13 | std::string name; // name of the set 14 | float tileWidth, tileHeight; // how big is a tile in the set 15 | TextureAsset *texture; // texture ref for the set 16 | }; 17 | } -------------------------------------------------------------------------------- /Core/Transform.cpp: -------------------------------------------------------------------------------- 1 | #include "Transform.h" 2 | #include "FileNode.h" 3 | 4 | #include "MonocleToolkit.h" 5 | #include 6 | #include 7 | 8 | namespace Monocle 9 | { 10 | Transform::Transform() 11 | : position(Vector2::zero), rotation(0.0f), scale(Vector2::one) 12 | { 13 | } 14 | 15 | Transform::Transform(const Transform &transform) 16 | : position(transform.position), rotation(transform.rotation), scale(transform.scale) 17 | { 18 | } 19 | 20 | void Transform::LerpTransform(Transform *prev, Transform *next, float percent) 21 | { 22 | position = next->position*percent + prev->position*(1.0f - percent); 23 | rotation = next->rotation*percent + prev->rotation*(1.0f - percent); 24 | scale = next->scale*percent + prev->scale*(1.0f-percent); 25 | } 26 | 27 | void Transform::Save(FileNode *fileNode) 28 | { 29 | if (position != Vector2::zero) 30 | fileNode->Write("position", position); 31 | if (rotation != 0) 32 | fileNode->Write("rotation", rotation); 33 | if (scale != Vector2::one) 34 | fileNode->Write("scale", scale); 35 | } 36 | 37 | void Transform::Load(FileNode *fileNode) 38 | { 39 | fileNode->Read("position", position); 40 | fileNode->Read("rotation", rotation); 41 | fileNode->Read("scale", scale); 42 | } 43 | 44 | Vector2 Transform::GetDirectionVector() 45 | { 46 | return Vector2(sin(rotation*pi / 180.0),cos(rotation*pi / 180.0)*-1.0); 47 | } 48 | } -------------------------------------------------------------------------------- /Core/Transform.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "Vector2.h" 4 | 5 | namespace Monocle 6 | { 7 | class FileNode; 8 | 9 | //! 10 | //! \brief Describes a transformation in 2D space, via position (horizontal (x) position, vertical (y) position), rotation (an angle) and scale (horizontal (x) size, vertical (y) size). 11 | //! 12 | class Transform 13 | { 14 | public: 15 | Transform(); 16 | Transform(const Transform &transform); 17 | 18 | virtual void Save(FileNode *fileNode); 19 | virtual void Load(FileNode *fileNode); 20 | 21 | //! Interpolate this Transform from prev and next, based on percent. (0.0 ... 1.0) 22 | void LerpTransform(Transform *prev, Transform *next, float percent); 23 | 24 | Vector2 position; 25 | float rotation; 26 | Vector2 scale; 27 | 28 | //! Retrieves a direction vector based on the rotation value. 29 | Vector2 GetDirectionVector(); 30 | }; 31 | } -------------------------------------------------------------------------------- /Core/Tween.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | //todo: replace list with something more portable 4 | #include 5 | #include "Vector2.h" 6 | #include "Color.h" 7 | 8 | namespace Monocle 9 | { 10 | enum EaseType 11 | { 12 | EASE_LINEAR=0, 13 | EASE_INOUTSIN, 14 | EASE_INSIN, 15 | EASE_OUTSIN, 16 | EASE_INQUAD, 17 | EASE_OUTQUAD, 18 | EASE_INOUTQUAD, 19 | EASE_INBOUNCE, 20 | EASE_OUTBOUNCE, 21 | EASE_INOUTBOUNCE, 22 | EASE_MAX 23 | }; 24 | 25 | class Tweener; 26 | 27 | class Tween 28 | { 29 | public: 30 | Tween(); 31 | 32 | // float 33 | static void To(float *value, const float &end, float time, EaseType easeType); 34 | static void FromTo(float *value, const float &start, const float &end, float time, EaseType easeType); 35 | 36 | // Vector2 37 | static void To(Vector2 *value, const Vector2 &end, float time, EaseType easeType); 38 | static void FromTo(Vector2 *value, const Vector2 &start, const Vector2 &end, float time, EaseType easeType); 39 | 40 | // Color 41 | static void To(Color *value, const Color &end, float time, EaseType easeType); 42 | static void FromTo(Color *value, const Color &start, const Color &end, float time, EaseType easeType); 43 | 44 | static void Update(); 45 | static void Clear(); 46 | static float Ease(float p, EaseType easeType); 47 | static void Remove(Tweener *tweener); 48 | 49 | private: 50 | template 51 | static void To(T *value, const T &end, float time, EaseType easeType); 52 | template 53 | static void FromTo(T *value, const T &start, const T &end, float time, EaseType easeType); 54 | 55 | static std::list tweeners; 56 | static std::list tweenersToRemove; 57 | }; 58 | 59 | class Tweener 60 | { 61 | protected: 62 | friend class Tween; 63 | 64 | Tweener(float time, EaseType easeType); 65 | 66 | float timer, time; 67 | EaseType easeType; 68 | 69 | void Update(); 70 | virtual void SetValue(float p)=0; 71 | }; 72 | 73 | class FloatTweener : public Tweener 74 | { 75 | private: 76 | friend class Tween; 77 | 78 | FloatTweener(float *value, float end, float time, EaseType easeType); 79 | void SetValue(float p); 80 | 81 | float *value, start, end; 82 | }; 83 | 84 | class Vector2Tweener : public Tweener 85 | { 86 | private: 87 | friend class Tween; 88 | 89 | Vector2Tweener(Vector2 *value, Vector2 end, float time, EaseType easeType); 90 | void SetValue(float p); 91 | 92 | Vector2 *value, start, end; 93 | }; 94 | 95 | class ColorTweener : public Tweener 96 | { 97 | private: 98 | friend class Tween; 99 | 100 | ColorTweener(Color *value, Color end, float time, EaseType easeType); 101 | void SetValue(float p); 102 | 103 | Color *value, start, end; 104 | }; 105 | } -------------------------------------------------------------------------------- /Core/Vector2.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | namespace Monocle 4 | { 5 | //! 6 | //! \brief 2 dimensional vector. (x and y coordinates) Can be used to represent directions and/or positions. 7 | //! 8 | class Vector2 9 | { 10 | public: 11 | float x,y; 12 | 13 | static Vector2 zero; 14 | static Vector2 one; 15 | static Vector2 down; 16 | static Vector2 up; 17 | static Vector2 left; 18 | static Vector2 right; 19 | 20 | Vector2(const Vector2 &vector2); 21 | Vector2(); 22 | Vector2(float x, float y); 23 | 24 | 25 | 26 | void Set(float x, float y); 27 | 28 | // return random vector 29 | static Vector2 Random(); 30 | static Vector2 Reflect(const Vector2& a, const Vector2& b); 31 | 32 | float GetSquaredMagnitude(); 33 | float GetMagnitude(); 34 | Vector2 GetNormalized(); 35 | void Normalize(); 36 | Vector2 GetPerpendicularLeft(); 37 | Vector2 GetPerpendicularRight(); 38 | void Clamp(float max); 39 | bool IsInRange(float range); 40 | float Dot(Vector2 other); 41 | float Cross(Vector2 other); 42 | Vector2 Reflect(const Vector2 &other); 43 | //! return angle in radians 44 | float GetAngleRadians(); 45 | float GetAngleDegrees(); 46 | //! initialize x and y from the passed angle in degrees 47 | void SetFromAngleDegrees(float angle); 48 | 49 | /* 50 | static Vector2 Add(Vector2 a, Vector2 b); 51 | static Vector2 Subtract(Vector2 a, Vector2 b); 52 | static Vector2 Multiply(Vector2 a, float s); 53 | static Vector2 Scale(Vector2 a, float s); 54 | */ 55 | 56 | Vector2 xx() const; 57 | Vector2 yy() const; 58 | Vector2 yx() const; 59 | 60 | float& operator[] (unsigned int i); 61 | 62 | Vector2& operator=(const Vector2& rhs); 63 | bool operator==(const Vector2& rhs); 64 | bool operator!=(const Vector2& rhs); 65 | 66 | Vector2& operator+=(const Vector2& rhs); 67 | Vector2& operator-=(const Vector2& rhs); 68 | Vector2& operator*=(float rhs); // scalar multiplication 69 | Vector2& operator/=(float rhs); // scalar inverse multiplication 70 | 71 | }; 72 | 73 | Vector2 operator+(const Vector2& lhs, const Vector2& rhs); 74 | Vector2 operator-(const Vector2& lhs, const Vector2& rhs); 75 | Vector2 operator-(const Vector2 &rhs); 76 | 77 | Vector2 operator*(float lhs, const Vector2& rhs); // left scalar multiplication 78 | Vector2 operator*(const Vector2& lhs, float rhs); // right scalar multiplication 79 | Vector2 operator/(const Vector2& lhs, float rhs); // right scalar inverse multiplication 80 | Vector2 operator/(float lhs, const Vector2 &rhs); 81 | 82 | Vector2 operator*(const Vector2& lhs, const Vector2& rhs); // multiply components (scale) 83 | //float operator^(const Vector2& lhs, const Vector2& rhs); // cross product 84 | } 85 | -------------------------------------------------------------------------------- /Core/Vector3.cpp: -------------------------------------------------------------------------------- 1 | #include "Vector3.h" 2 | 3 | namespace Monocle 4 | { 5 | Vector3 Vector3::zero = Vector3(0,0,0); 6 | Vector3 Vector3::one = Vector3(1,1,1); 7 | Vector3 Vector3::down = Vector3(0, -1, 0); 8 | Vector3 Vector3::up = Vector3(0, 1, 0); 9 | Vector3 Vector3::left = Vector3(-1, 0, 0); 10 | Vector3 Vector3::right = Vector3(1, 0, 0); 11 | 12 | Vector3::Vector3() 13 | : x(0.0f), y(0.0f), z(0.0f) 14 | { 15 | 16 | } 17 | 18 | Vector3::Vector3(float x, float y, float z) 19 | : x(x), y(y), z(z) 20 | { 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /Core/Vector3.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | namespace Monocle 4 | { 5 | //! 6 | //! 3 dimensional vector class. Not fully implemented yet. 7 | //! 8 | class Vector3 9 | { 10 | public: 11 | float x,y,z; 12 | 13 | static Vector3 zero; 14 | static Vector3 one; 15 | static Vector3 down; 16 | static Vector3 up; 17 | static Vector3 left; 18 | static Vector3 right; 19 | 20 | Vector3(); 21 | Vector3(float x, float y, float z); 22 | 23 | /* 24 | float GetSquaredMagnitude(); 25 | float GetMagnitude(); 26 | Vector2 GetNormalized(); 27 | void Normalize(); 28 | Vector2 GetPerpendicularLeft(); 29 | Vector2 GetPerpendicularRight(); 30 | void Clamp(float max); 31 | bool IsInRange(float range); 32 | float Dot(Vector2 other); 33 | */ 34 | 35 | /* 36 | static Vector2 Add(Vector2 a, Vector2 b); 37 | static Vector2 Subtract(Vector2 a, Vector2 b); 38 | static Vector2 Multiply(Vector2 a, float s); 39 | static Vector2 Scale(Vector2 a, float s); 40 | */ 41 | 42 | }; 43 | } -------------------------------------------------------------------------------- /Core/Windows/WindowsPlatform.h: -------------------------------------------------------------------------------- 1 | #ifdef MONOCLE_WINDOWS 2 | 3 | #pragma once 4 | 5 | #include "../Platform.h" 6 | 7 | #define WIN32_LEAN_AND_MEAN 8 | #include 9 | 10 | namespace Monocle 11 | { 12 | class WindowsPlatform 13 | { 14 | public: 15 | 16 | HGLRC hRC; // Permanent Rendering Context 17 | HDC hDC; // Private GDI Device Context 18 | HWND hWnd; // Holds Our Window Handle 19 | HINSTANCE hInstance; // Holds The Instance Of The Application 20 | 21 | //bool active; // Window Active Flag Set To TRUE By Default 22 | bool fullscreen; // Fullscreen Flag Set To Fullscreen Mode By Default 23 | 24 | static WindowsPlatform* instance; 25 | Platform *platform; 26 | 27 | WindowsPlatform() 28 | : hRC(NULL), 29 | hDC(NULL), 30 | hWnd(NULL), 31 | hInstance(NULL) 32 | { 33 | //active = true; 34 | fullscreen = true; 35 | instance = this; 36 | } 37 | 38 | bool CreatePlatformWindow(const char* title, int width, int height, int bits, bool fullscreenflag); 39 | void KillPlatformWindow(); 40 | static LRESULT CALLBACK WndProc( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam); 41 | void CenterWindow(); 42 | static void GetDesktopSize(int *width, int *height); 43 | }; 44 | 45 | } 46 | 47 | #endif -------------------------------------------------------------------------------- /Core/XML/XMLFileNode.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "../FileNode.h" 4 | //#include "tinyxml.h" 5 | 6 | class TiXmlElement; 7 | 8 | 9 | namespace Monocle 10 | { 11 | class Entity; 12 | 13 | class XMLFileNode : public FileNode 14 | { 15 | public: 16 | XMLFileNode(); 17 | XMLFileNode(TiXmlElement *element); 18 | ~XMLFileNode(); 19 | 20 | void Write(const std::string &name, const int &value); 21 | void Write(const std::string &name, const float &value); 22 | void Write(const std::string &name, const std::string &value); 23 | void Write(const std::string &name, const Vector2 &value); 24 | void Write(const std::string &name, const Color &value); 25 | void Write(const std::string &name, const bool &value); 26 | 27 | void Read(const std::string &name, int &value); 28 | void Read(const std::string &name, float &value); 29 | void Read(const std::string &name, std::string &value); 30 | void Read(const std::string &name, Vector2 &value); 31 | void Read(const std::string &name, Color &value); 32 | void Read(const std::string &name, bool &value); 33 | 34 | FileNode* FirstChildNode(const std::string &name); 35 | FileNode* NextChildNode(const std::string &name); 36 | 37 | void SaveChildNode(const std::string &name, Entity *entity); 38 | 39 | //FileNode* NewNode(const std::string &name); 40 | //FileNode* InsertEndChildNode(FileNode *fileNode); 41 | 42 | TiXmlElement *element; 43 | //TiXmlElement *managed; 44 | 45 | XMLFileNode *iterator; 46 | }; 47 | } 48 | -------------------------------------------------------------------------------- /Core/premake4-monocle.lua: -------------------------------------------------------------------------------- 1 | -- Monocle Library 2 | project "MonocleCore" 3 | kind "StaticLib" 4 | language "C++" 5 | 6 | monocle_os_defines(); 7 | monocle_os_includedirs(); 8 | 9 | basedir ( _BUILD_BASE ) 10 | 11 | files { "**.h", "**.cpp", "**.c" } 12 | 13 | files { _MONOCLE_EXTLIB_BASE.."/stb/**.c" } 14 | files { _MONOCLE_EXTLIB_BASE.."/TinyXML/**.cpp" } 15 | files { _MONOCLE_EXTLIB_BASE.."/GL/glew.c" } 16 | --files { _MONOCLE_EXTLIB_BASE.."/lua/**.c" } 17 | 18 | configuration "macosx" 19 | files { "**.mm" } 20 | 21 | --links{ "TinyXML" } 22 | 23 | configuration "Debug" 24 | defines { "DEBUG" } 25 | flags { "Symbols" } 26 | targetsuffix "Debug" 27 | 28 | configuration "Release" 29 | defines { "NDEBUG" } 30 | flags { "Optimize" } 31 | 32 | 33 | -- Old TinyXML Project (source just added to Core for now) 34 | --[[ 35 | project "TinyXML" 36 | kind "StaticLib" 37 | language "C++" 38 | 39 | monocle_os_defines(); 40 | monocle_os_includedirs(); 41 | 42 | basedir ( _BUILD_BASE.."/TinyXML" ) 43 | 44 | files { _MONOCLE_EXTLIB_BASE.."/TinyXML/**.h", _MONOCLE_EXTLIB_BASE.."/TinyXML/**.cpp" } 45 | 46 | configuration "Debug" 47 | defines { "DEBUG" } 48 | flags { "Symbols" } 49 | 50 | configuration "Release" 51 | defines { "NDEBUG" } 52 | flags { "Optimize" } 53 | ]]-- -------------------------------------------------------------------------------- /Libraries/AL/xram.h: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | // X-RAM Function pointer definitions 4 | typedef ALboolean (__cdecl *EAXSetBufferMode)(ALsizei n, ALuint *buffers, ALint value); 5 | typedef ALenum (__cdecl *EAXGetBufferMode)(ALuint buffer, ALint *value); 6 | 7 | ////////////////////////////////////////////////////////////////////////////// 8 | // Query for X-RAM extension 9 | // 10 | // if (alIsExtensionPresent("EAX-RAM") == AL_TRUE) 11 | // X-RAM Extension found 12 | // 13 | ////////////////////////////////////////////////////////////////////////////// 14 | 15 | 16 | ////////////////////////////////////////////////////////////////////////////// 17 | // X-RAM enum names 18 | // 19 | // "AL_EAX_RAM_SIZE" 20 | // "AL_EAX_RAM_FREE" 21 | // "AL_STORAGE_AUTOMATIC" 22 | // "AL_STORAGE_HARDWARE" 23 | // "AL_STORAGE_ACCESSIBLE" 24 | // 25 | // Query enum values using alGetEnumValue, for example 26 | // 27 | // long lRamSizeEnum = alGetEnumValue("AL_EAX_RAM_SIZE") 28 | // 29 | ////////////////////////////////////////////////////////////////////////////// 30 | 31 | 32 | ////////////////////////////////////////////////////////////////////////////// 33 | // Query total amount of X-RAM 34 | // 35 | // long lTotalSize = alGetInteger(alGetEnumValue("AL_EAX_RAM_SIZE") 36 | // 37 | ////////////////////////////////////////////////////////////////////////////// 38 | 39 | 40 | ////////////////////////////////////////////////////////////////////////////// 41 | // Query free X-RAM available 42 | // 43 | // long lFreeSize = alGetInteger(alGetEnumValue("AL_EAX_RAM_FREE") 44 | // 45 | ////////////////////////////////////////////////////////////////////////////// 46 | 47 | 48 | ////////////////////////////////////////////////////////////////////////////// 49 | // Query X-RAM Function pointers 50 | // 51 | // Use typedefs defined above to get the X-RAM function pointers using 52 | // alGetProcAddress 53 | // 54 | // EAXSetBufferMode eaxSetBufferMode; 55 | // EAXGetBufferMode eaxGetBufferMode; 56 | // 57 | // eaxSetBufferMode = (EAXSetBufferMode)alGetProcAddress("EAXSetBufferMode"); 58 | // eaxGetBufferMode = (EAXGetBufferMode)alGetProcAddress("EAXGetBufferMode"); 59 | // 60 | ////////////////////////////////////////////////////////////////////////////// 61 | 62 | 63 | ////////////////////////////////////////////////////////////////////////////// 64 | // Force an Open AL Buffer into X-RAM (good for non-streaming buffers) 65 | // 66 | // ALuint uiBuffer; 67 | // alGenBuffers(1, &uiBuffer); 68 | // eaxSetBufferMode(1, &uiBuffer, alGetEnumValue("AL_STORAGE_HARDWARE")); 69 | // alBufferData(...); 70 | // 71 | ////////////////////////////////////////////////////////////////////////////// 72 | 73 | 74 | ////////////////////////////////////////////////////////////////////////////// 75 | // Force an Open AL Buffer into 'accessible' (currently host) RAM (good for streaming buffers) 76 | // 77 | // ALuint uiBuffer; 78 | // alGenBuffers(1, &uiBuffer); 79 | // eaxSetBufferMode(1, &uiBuffer, alGetEnumValue("AL_STORAGE_ACCESSIBLE")); 80 | // alBufferData(...); 81 | // 82 | ////////////////////////////////////////////////////////////////////////////// 83 | 84 | 85 | ////////////////////////////////////////////////////////////////////////////// 86 | // Put an Open AL Buffer into X-RAM if memory is available, otherwise use 87 | // host RAM. This is the default mode. 88 | // 89 | // ALuint uiBuffer; 90 | // alGenBuffers(1, &uiBuffer); 91 | // eaxSetBufferMode(1, &uiBuffer, alGetEnumValue("AL_STORAGE_AUTOMATIC")); 92 | // alBufferData(...); 93 | // 94 | ////////////////////////////////////////////////////////////////////////////// -------------------------------------------------------------------------------- /Libraries/Compiled/MacOSX/adjust.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | install_name_tool -id @executable_path/../Frameworks/$1.framework/$1 ./$1.framework/$1 4 | -------------------------------------------------------------------------------- /Libraries/Compiled/MacOSX/libGLEW.a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zaphire/Monocle-Engine/a4558b5436681ab0ec95aec388cbb791b26f0b81/Libraries/Compiled/MacOSX/libGLEW.a -------------------------------------------------------------------------------- /Libraries/Compiled/MacOSX/libogg.a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zaphire/Monocle-Engine/a4558b5436681ab0ec95aec388cbb791b26f0b81/Libraries/Compiled/MacOSX/libogg.a -------------------------------------------------------------------------------- /Libraries/Compiled/MacOSX/libvorbis.a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zaphire/Monocle-Engine/a4558b5436681ab0ec95aec388cbb791b26f0b81/Libraries/Compiled/MacOSX/libvorbis.a -------------------------------------------------------------------------------- /Libraries/Compiled/MacOSX/libvorbisenc.a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zaphire/Monocle-Engine/a4558b5436681ab0ec95aec388cbb791b26f0b81/Libraries/Compiled/MacOSX/libvorbisenc.a -------------------------------------------------------------------------------- /Libraries/Compiled/MacOSX/libvorbisfile.a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zaphire/Monocle-Engine/a4558b5436681ab0ec95aec388cbb791b26f0b81/Libraries/Compiled/MacOSX/libvorbisfile.a -------------------------------------------------------------------------------- /Libraries/Compiled/Win32/EFX-Util_MT/EFX-Util.lib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zaphire/Monocle-Engine/a4558b5436681ab0ec95aec388cbb791b26f0b81/Libraries/Compiled/Win32/EFX-Util_MT/EFX-Util.lib -------------------------------------------------------------------------------- /Libraries/Compiled/Win32/EFX-Util_MTDLL/EFX-Util.lib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zaphire/Monocle-Engine/a4558b5436681ab0ec95aec388cbb791b26f0b81/Libraries/Compiled/Win32/EFX-Util_MTDLL/EFX-Util.lib -------------------------------------------------------------------------------- /Libraries/Compiled/Win32/OpenAL32.lib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zaphire/Monocle-Engine/a4558b5436681ab0ec95aec388cbb791b26f0b81/Libraries/Compiled/Win32/OpenAL32.lib -------------------------------------------------------------------------------- /Libraries/Compiled/Win32/glew32s.lib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zaphire/Monocle-Engine/a4558b5436681ab0ec95aec388cbb791b26f0b81/Libraries/Compiled/Win32/glew32s.lib -------------------------------------------------------------------------------- /Libraries/Compiled/Win32/libogg_static.lib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zaphire/Monocle-Engine/a4558b5436681ab0ec95aec388cbb791b26f0b81/Libraries/Compiled/Win32/libogg_static.lib -------------------------------------------------------------------------------- /Libraries/Compiled/Win32/libvorbis_static.lib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zaphire/Monocle-Engine/a4558b5436681ab0ec95aec388cbb791b26f0b81/Libraries/Compiled/Win32/libvorbis_static.lib -------------------------------------------------------------------------------- /Libraries/Compiled/Win32/libvorbisfile_static.lib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zaphire/Monocle-Engine/a4558b5436681ab0ec95aec388cbb791b26f0b81/Libraries/Compiled/Win32/libvorbisfile_static.lib -------------------------------------------------------------------------------- /Libraries/TinyXML/tinyxmlerror.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | www.sourceforge.net/projects/tinyxml 3 | Original code (2.0 and earlier )copyright (c) 2000-2006 Lee Thomason (www.grinninglizard.com) 4 | 5 | This software is provided 'as-is', without any express or implied 6 | warranty. In no event will the authors be held liable for any 7 | damages arising from the use of this software. 8 | 9 | Permission is granted to anyone to use this software for any 10 | purpose, including commercial applications, and to alter it and 11 | redistribute it freely, subject to the following restrictions: 12 | 13 | 1. The origin of this software must not be misrepresented; you must 14 | not claim that you wrote the original software. If you use this 15 | software in a product, an acknowledgment in the product documentation 16 | would be appreciated but is not required. 17 | 18 | 2. Altered source versions must be plainly marked as such, and 19 | must not be misrepresented as being the original software. 20 | 21 | 3. This notice may not be removed or altered from any source 22 | distribution. 23 | */ 24 | 25 | #include "tinyxml.h" 26 | 27 | // The goal of the seperate error file is to make the first 28 | // step towards localization. tinyxml (currently) only supports 29 | // english error messages, but the could now be translated. 30 | // 31 | // It also cleans up the code a bit. 32 | // 33 | 34 | const char* TiXmlBase::errorString[ TIXML_ERROR_STRING_COUNT ] = 35 | { 36 | "No error", 37 | "Error", 38 | "Failed to open file", 39 | "Error parsing Element.", 40 | "Failed to read Element name", 41 | "Error reading Element value.", 42 | "Error reading Attributes.", 43 | "Error: empty tag.", 44 | "Error reading end tag.", 45 | "Error parsing Unknown.", 46 | "Error parsing Comment.", 47 | "Error parsing Declaration.", 48 | "Error document empty.", 49 | "Error null (0) or unexpected EOF found in input stream.", 50 | "Error parsing CDATA.", 51 | "Error when TiXmlDocument added to document, because TiXmlDocument can only be at the root.", 52 | }; 53 | -------------------------------------------------------------------------------- /Project/Xcode4/MonocleTest/Monocle.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /Project/Xcode4/MonocleTest/Monocle.xcodeproj/project.xcworkspace/xcuserdata/josh.xcuserdatad/WorkspaceSettings.xcsettings: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | IDEWorkspaceUserSettings_BuildLocationStyle 6 | 0 7 | IDEWorkspaceUserSettings_BuildSubfolderNameStyle 8 | 0 9 | IDEWorkspaceUserSettings_DerivedDataLocationStyle 10 | 0 11 | IDEWorkspaceUserSettings_HasAskedToTakeAutomaticSnapshotBeforeSignificantChanges 12 | 13 | IDEWorkspaceUserSettings_LiveSourceIssuesEnabled 14 | 15 | IDEWorkspaceUserSettings_SnapshotAutomaticallyBeforeSignificantChanges 16 | 17 | IDEWorkspaceUserSettings_SnapshotLocationStyle 18 | 0 19 | 20 | 21 | -------------------------------------------------------------------------------- /Project/Xcode4/MonocleTest/Monocle.xcodeproj/xcshareddata/xcschemes/Monocle.xcscheme: -------------------------------------------------------------------------------- 1 | 2 | 4 | 7 | 8 | 14 | 20 | 21 | 22 | 23 | 24 | 29 | 30 | 31 | 32 | 40 | 41 | 42 | 43 | 50 | 51 | 53 | 54 | 57 | 58 | 59 | -------------------------------------------------------------------------------- /Project/Xcode4/MonocleTest/Monocle.xcodeproj/xcuserdata/josh.xcuserdatad/xcdebugger/Breakpoints.xcbkptlist: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | -------------------------------------------------------------------------------- /Project/Xcode4/MonocleTest/Monocle.xcodeproj/xcuserdata/josh.xcuserdatad/xcschemes/xcschememanagement.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | SchemeUserState 6 | 7 | Monocle.xcscheme_^#shared#^_ 8 | 9 | orderHint 10 | 0 11 | 12 | 13 | SuppressBuildableAutocreation 14 | 15 | 0328F44C136DAB6100639FB1 16 | 17 | primary 18 | 19 | 20 | 03B6BFB4136C758A00E40253 21 | 22 | primary 23 | 24 | 25 | 03B6BFC2136C771F00E40253 26 | 27 | primary 28 | 29 | 30 | 37EA2495132F986900D216B0 31 | 32 | primary 33 | 34 | 35 | 36 | 37 | 38 | -------------------------------------------------------------------------------- /Project/Xcode4/MonocleTest/Monocle/Monocle-Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | English 7 | CFBundleExecutable 8 | ${EXECUTABLE_NAME} 9 | CFBundleIconFile 10 | 11 | CFBundleIdentifier 12 | org.monoclepowered.${PRODUCT_NAME:rfc1034identifier} 13 | CFBundleInfoDictionaryVersion 14 | 6.0 15 | CFBundleName 16 | ${PRODUCT_NAME} 17 | CFBundlePackageType 18 | FMWK 19 | CFBundleShortVersionString 20 | 1.0 21 | CFBundleSignature 22 | ???? 23 | CFBundleVersion 24 | 1 25 | NSHumanReadableCopyright 26 | MonoclePowered.org! All rights for looking good in a single-lens reserved. 27 | NSPrincipalClass 28 | 29 | 30 | 31 | -------------------------------------------------------------------------------- /Project/Xcode4/MonocleTest/Monocle/Monocle-Prefix.pch: -------------------------------------------------------------------------------- 1 | // 2 | // Prefix header for all source files of the 'Monocle' target in the 'Monocle' project 3 | // 4 | 5 | #ifdef __OBJC__ 6 | #import 7 | #endif 8 | -------------------------------------------------------------------------------- /Project/Xcode4/MonocleTest/Monocle/en.lproj/InfoPlist.strings: -------------------------------------------------------------------------------- 1 | /* Localized versions of Info.plist keys */ 2 | 3 | -------------------------------------------------------------------------------- /Project/Xcode4/MonocleTest/MonocleTests/MonocleTests.xcodeproj/xcshareddata/xcschemes/Monocle Tests.xcscheme: -------------------------------------------------------------------------------- 1 | 2 | 4 | 7 | 8 | 14 | 20 | 21 | 22 | 23 | 24 | 29 | 30 | 31 | 32 | 40 | 41 | 47 | 48 | 49 | 50 | 54 | 55 | 59 | 60 | 61 | 62 | 63 | 64 | 71 | 72 | 78 | 79 | 80 | 81 | 83 | 84 | 87 | 88 | 89 | -------------------------------------------------------------------------------- /Project/Xcode4/MonocleTest/MonocleTests/MonocleTests.xcodeproj/xcuserdata/josh.xcuserdatad/xcschemes/xcschememanagement.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | SchemeUserState 6 | 7 | Monocle Tests.xcscheme_^#shared#^_ 8 | 9 | orderHint 10 | 1 11 | 12 | 13 | SuppressBuildableAutocreation 14 | 15 | 031150FC136EF946002E27C2 16 | 17 | primary 18 | 19 | 20 | 03115111136EF9EA002E27C2 21 | 22 | primary 23 | 24 | 25 | 03115134136EFB74002E27C2 26 | 27 | primary 28 | 29 | 30 | 03836F23136EED5D006746F2 31 | 32 | primary 33 | 34 | 35 | 03836F90136EF205006746F2 36 | 37 | primary 38 | 39 | 40 | 41 | 42 | 43 | -------------------------------------------------------------------------------- /Project/Xcode4/MonocleTest/MonocleTests/MonocleTests/MonocleTests-Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | ${EXECUTABLE_NAME} 9 | CFBundleIconFile 10 | 11 | CFBundleIdentifier 12 | org.monoclepowered.${PRODUCT_NAME:rfc1034identifier} 13 | CFBundleInfoDictionaryVersion 14 | 6.0 15 | CFBundleName 16 | ${PRODUCT_NAME} 17 | CFBundlePackageType 18 | APPL 19 | CFBundleShortVersionString 20 | 1.0 21 | CFBundleSignature 22 | ???? 23 | CFBundleVersion 24 | 1 25 | LSMinimumSystemVersion 26 | ${MACOSX_DEPLOYMENT_TARGET} 27 | NSPrincipalClass 28 | NSApplication 29 | 30 | 31 | -------------------------------------------------------------------------------- /Project/Xcode4/MonocleTest/MonocleTests/MonocleTests/MonocleTests-Prefix.pch: -------------------------------------------------------------------------------- 1 | // 2 | // Prefix header for all source files of the 'Monocle Tests' target in the 'Monocle Tests' project 3 | // 4 | 5 | #ifdef __OBJC__ 6 | #import 7 | #endif 8 | -------------------------------------------------------------------------------- /Project/Xcode4/MonocleTest/MonocleTests/MonocleTests/en.lproj/InfoPlist.strings: -------------------------------------------------------------------------------- 1 | /* Localized versions of Info.plist keys */ 2 | 3 | -------------------------------------------------------------------------------- /README: -------------------------------------------------------------------------------- 1 | _ _ 2 | | | (_) 3 | ____ ___ ____ ___ ____| | ____ ____ ____ ____ _ ____ ____ 4 | | \ / _ \| _ \ / _ \ / ___) |/ _ ) / _ ) _ \ / _ | | _ \ / _ ) 5 | | | | | |_| | | | | |_| ( (___| ( (/ / ( (/ /| | | ( ( | | | | | ( (/ / 6 | |_|_|_|\___/|_| |_|\___/ \____)_|\____) \____)_| |_|\_|| |_|_| |_|\____) 7 | (_____| 8 | 9 | MIT License 10 | 11 | Permission is hereby granted, free of charge, to any person obtaining a copy 12 | of this software and associated documentation files (the "Software"), to deal 13 | in the Software without restriction, including without limitation the rights 14 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 15 | copies of the Software, and to permit persons to whom the Software is 16 | furnished to do so, subject to the following conditions: 17 | 18 | The above copyright notice and this permission notice shall be included in 19 | all copies or substantial portions of the Software. 20 | 21 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 22 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 23 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 24 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 25 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 26 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 27 | THE SOFTWARE. 28 | 29 | == Branches == 30 | 31 | "development" - the latest code 32 | "master" - the last 'stable' code 33 | 34 | i.e. If you want to check out the latest, grab "development." 35 | 36 | == Building == 37 | 38 | To build Monocle, use one of the included project files. 39 | 40 | If there is no project file for your platform, generate one automatically using Premake4. 41 | 42 | See: http://industriousone.com/premake 43 | 44 | Run: premake4.exe --help 45 | to see all options. 46 | 47 | Windows: 48 | Generate Windows project files with Premake4. To do this, you must download premake4.exe. 49 | Place it in your root Monocle-Engine directory. Then run it with commands through the 50 | Windows commandline. (cmd.exe) 51 | 52 | e.g. To generate project files for vs2010, including tests 53 | 54 | run: 55 | premake4.exe --testapp=all vs2010 56 | in the Monocle-Engine root directory. 57 | 58 | The project files will show up in Build/gen-vs2010-All and Build/gen-vs2010-Monocle 59 | 60 | To run tests on Windows, make sure the project's working directory is set to: 61 | $(SolutionDir)..\..\..\Build\bin\ 62 | 63 | Mac OSX: 64 | You can use the XCode project file included. 65 | Make sure you're using XCode version 4 and that you have the shared Scheme selected. 66 | 67 | Linux: 68 | Generate makefiles with Premake4. 69 | They will show up in Build/gen-* 70 | 71 | Tests: 72 | Change premake4 commandline to build a project file with tests included. 73 | 74 | == Test Controls == 75 | 76 | Updated test controls coming soon... 77 | -------------------------------------------------------------------------------- /Samples/All/premake4-All.lua: -------------------------------------------------------------------------------- 1 | 2 | function monocletest_do_project_test( name ) 3 | _OPTIONS["testapp"] = name 4 | 5 | _TESTAPP_PREMAKE_GENERIC_SCRIPT = "../premake4-test-generic.lua" 6 | _TESTAPP_PREMAKE_SCRIPT = "../".._OPTIONS["testapp"].."/premake4-".._OPTIONS["testapp"]..".lua" 7 | 8 | if os.isfile( _TESTAPP_PREMAKE_SCRIPT ) then 9 | dofile( _TESTAPP_PREMAKE_SCRIPT ) 10 | else 11 | dofile( _TESTAPP_PREMAKE_GENERIC_SCRIPT ) 12 | end 13 | end 14 | 15 | monocletest_do_project_test( "Pong" ) 16 | monocletest_do_project_test( "AudioTest" ) 17 | monocletest_do_project_test( "Flash" ) 18 | monocletest_do_project_test( "Jumper" ) 19 | monocletest_do_project_test( "LevelEditor" ) 20 | monocletest_do_project_test( "Ogmo" ) 21 | monocletest_do_project_test( "PuppetTest" ) 22 | monocletest_do_project_test( "Scripted" ) 23 | monocletest_do_project_test( "TestSelector" ) 24 | 25 | -------------------------------------------------------------------------------- /Samples/AudioTest/AudioTest.h: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace Monocle; 4 | 5 | namespace AudioTest 6 | { 7 | class Text: public Entity 8 | { 9 | public: 10 | Text(const std::string& text, FontAsset* font); 11 | 12 | void Render(); 13 | 14 | void SetFont(FontAsset* font) { this->font = font; } 15 | void SetText(const std::string& text) { this->text = text; } 16 | 17 | protected: 18 | FontAsset* font; 19 | std::string text; 20 | }; 21 | 22 | class Waveform: public Entity 23 | { 24 | public: 25 | Waveform( AudioDeck *deck, int type = 0 ); 26 | 27 | void Render(); 28 | 29 | protected: 30 | 31 | int type; 32 | AudioDeck *deck; 33 | }; 34 | 35 | class GameScene : public Scene 36 | { 37 | public: 38 | 39 | Text *scText; 40 | 41 | void Begin(); 42 | void End(); 43 | void Update(); 44 | 45 | void ReceiveNote(const std::string ¬e); 46 | }; 47 | } -------------------------------------------------------------------------------- /Samples/AudioTest/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | set(AUDIOTEST_SRCS 2 | Main.cpp AudioTest.cpp 3 | ) 4 | 5 | add_executable(TestAudio ${AUDIOTEST_SRCS}) 6 | 7 | target_link_Libraries(TestAudio MonocleCore ${CORE_LINK}) 8 | -------------------------------------------------------------------------------- /Samples/AudioTest/Main.cpp: -------------------------------------------------------------------------------- 1 | #include "Monocle.h" 2 | #include "AudioTest.h" 3 | 4 | using namespace Monocle; 5 | 6 | int main(void) 7 | { 8 | Game *game = new Game(); 9 | game->SetScene(new AudioTest::GameScene()); 10 | game->Main(); 11 | delete game; 12 | return 0; 13 | } 14 | -------------------------------------------------------------------------------- /Samples/Flash/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | set(FLASH_SRCS 2 | Main.cpp Flash.cpp 3 | ) 4 | 5 | add_executable(TestFlash ${FLASH_SRCS}) 6 | 7 | target_link_Libraries(TestFlash MonocleCore ${CORE_LINK}) 8 | -------------------------------------------------------------------------------- /Samples/Flash/Main.cpp: -------------------------------------------------------------------------------- 1 | #include "Monocle.h" 2 | #include "Flash.h" 3 | 4 | using namespace Monocle; 5 | 6 | int main(void) 7 | { 8 | Game *game = new Game(); 9 | Assets::SetContentPath(Assets::GetContentPath()+"/Flash/"); 10 | game->SetScene(new Flash::TestScene()); 11 | game->Main(); 12 | delete game; 13 | return 0; 14 | } 15 | -------------------------------------------------------------------------------- /Samples/Jumper/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | set(JUMPER_SRCS 2 | Main.cpp Jumper.cpp 3 | ) 4 | 5 | add_executable(TestJumper ${JUMPER_SRCS}) 6 | 7 | target_link_libraries(TestJumper MonocleCore ${CORE_LINK}) 8 | 9 | -------------------------------------------------------------------------------- /Samples/Jumper/Jumper.h: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | // by @NoelFB 6 | using namespace Monocle; 7 | 8 | namespace Jumper 9 | { 10 | /* 11 | class Mover : public Sprite 12 | { 13 | public: 14 | Mover(int layer, std::string graphic, Vector2 pos, float scale); 15 | void Update(); 16 | 17 | Vector2 velocity; 18 | }; 19 | */ 20 | 21 | class Player : public Entity 22 | { 23 | public: 24 | Player(Vector2 pos); 25 | void Update(); 26 | float Sign(float i, float to); 27 | 28 | KeyCode keyUp; 29 | KeyCode keyRight; 30 | KeyCode keyLeft; 31 | 32 | Vector2 velocity; 33 | float gravity; 34 | float speed; 35 | bool onGround; 36 | float jump; 37 | float maxSpeed; 38 | bool isJumping; 39 | 40 | float leanAmount; // how much does he lean into his left/right movement? 41 | 42 | Sprite *sprite; 43 | }; 44 | 45 | 46 | class Wall : public Entity 47 | { 48 | public: 49 | Wall(Vector2 p, float w, float h); 50 | //void Update(); 51 | void Render(); 52 | 53 | //temporary, replace base class with Sprite eventually 54 | float width, height; 55 | }; 56 | 57 | class GameScene : public Scene 58 | { 59 | public: 60 | Player *player; 61 | Wall *wall; 62 | 63 | void Begin(); 64 | void End(); 65 | void Update(); 66 | 67 | void SpawnPlayer(Vector2 pos); 68 | }; 69 | } 70 | -------------------------------------------------------------------------------- /Samples/Jumper/Main.cpp: -------------------------------------------------------------------------------- 1 | #include "Monocle.h" 2 | #include "Jumper.h" 3 | 4 | using namespace Monocle; 5 | 6 | int main(void) 7 | { 8 | Game *game = new Game(); 9 | Assets::SetContentPath(Assets::GetContentPath()+"/Jumper/"); 10 | game->SetScene(new Jumper::GameScene()); 11 | game->Main(); 12 | delete game; 13 | return 0; 14 | } 15 | -------------------------------------------------------------------------------- /Samples/LevelEditor/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | set(TEST_LEVELEDITOR_SRCS 2 | Main.cpp LevelEditorTest.cpp 3 | ) 4 | 5 | add_executable(TestLevelEditor ${TEST_LEVELEDITOR_SRCS}) 6 | 7 | target_link_Libraries(TestLevelEditor MonocleCore ${CORE_LINK}) 8 | -------------------------------------------------------------------------------- /Samples/LevelEditor/LevelEditorTest.cpp: -------------------------------------------------------------------------------- 1 | #include "LevelEditorTest.h" 2 | 3 | namespace LevelEditorTest 4 | { 5 | 6 | Player::Player() 7 | : Entity(), force(200.0f) 8 | { 9 | SetGraphic(new Sprite("graphics/player.png")); 10 | scale = Vector2::one * 0.5f; 11 | } 12 | 13 | void Player::Update() 14 | { 15 | Entity::Update(); 16 | 17 | if (Input::IsMouseButtonHeld(MOUSE_BUTTON_LEFT)) 18 | { 19 | Vector2 dir = Input::GetWorldMousePosition() - position; 20 | dir.Normalize(); 21 | velocity += force * dir * Monocle::deltaTime; 22 | } 23 | 24 | position += velocity * Monocle::deltaTime; 25 | 26 | Scene::GetCamera()->position = position; 27 | //Graphics::SetCameraPosition(position); 28 | } 29 | 30 | 31 | LevelScene *levelScene = NULL; 32 | 33 | LevelScene::LevelScene() 34 | : Scene(), levelEditor(NULL)//, puppetEditor(NULL) 35 | { 36 | } 37 | 38 | void LevelScene::Begin() 39 | { 40 | // init instance pointer 41 | levelScene = this; 42 | 43 | // call the super 44 | Scene::Begin(); 45 | 46 | // set the background color to a dark blue (10% blue + 90% black) 47 | Graphics::SetBackgroundColor(Color::blue*0.1f + Color::black*0.9f); 48 | 49 | // create new LevelEditor and Add it to the scene 50 | Add( levelEditor = new LevelEditor() ); 51 | 52 | // create new PuppetEditor and Add it to the scene 53 | //Add( puppetEditor = new PuppetEditor() ); 54 | // disable it 55 | //puppetEditor->Disable(); 56 | 57 | 58 | // pause this scene's updating (freeze the game) 59 | isPaused = true; 60 | 61 | // load project file that defines our tilesets 62 | Level::LoadProject("project.xml"); 63 | 64 | // load the actual level 65 | Level::Load("level.xml", this); 66 | 67 | // create the player 68 | Player *player = new Player(); 69 | player->position = Graphics::GetScreenCenter(); 70 | Add(player); 71 | } 72 | 73 | void LevelScene::Update() 74 | { 75 | Scene::Update(); 76 | 77 | if (Input::IsKeyPressed(KEY_S) && Input::IsKeyHeld(KEY_LCTRL)) 78 | { 79 | Level::Save(); 80 | } 81 | 82 | // if we hit tab... 83 | if (Input::IsKeyPressed(KEY_TAB)) 84 | { 85 | // if we're not doing anything in the levelEditor... 86 | if (levelEditor->GetState() == FTES_NONE) 87 | { 88 | // toggle pause state 89 | isPaused = !isPaused; 90 | 91 | if (isPaused) 92 | levelEditor->Enable(); 93 | else 94 | levelEditor->Disable(); 95 | } 96 | } 97 | 98 | // if we hit CTRL+A 99 | /* 100 | if (Input::IsKeyHeld(KEY_LCTRL) && Input::IsKeyPressed(KEY_A)) 101 | { 102 | if (!isPaused) isPaused = true; 103 | 104 | levelEditor->Disable(); 105 | puppetEditor->Enable(); 106 | } 107 | */ 108 | } 109 | 110 | void LevelScene::End() 111 | { 112 | levelEditor = NULL; 113 | //puppetEditor = NULL; 114 | 115 | Scene::End(); 116 | } 117 | } 118 | -------------------------------------------------------------------------------- /Samples/LevelEditor/LevelEditorTest.h: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | using namespace Monocle; 6 | 7 | // Test the FringeTileEditor 8 | namespace LevelEditorTest 9 | { 10 | class Player : public Entity 11 | { 12 | public: 13 | Player(); 14 | void Update(); 15 | Vector2 velocity; 16 | float force; 17 | }; 18 | 19 | class LevelScene : public Scene 20 | { 21 | public: 22 | LevelScene(); 23 | void Begin(); 24 | void Update(); 25 | void End(); 26 | 27 | LevelEditor *levelEditor; 28 | //PuppetEditor *puppetEditor; 29 | }; 30 | 31 | extern LevelScene *levelScene; 32 | }; 33 | -------------------------------------------------------------------------------- /Samples/LevelEditor/Main.cpp: -------------------------------------------------------------------------------- 1 | #include "Monocle.h" 2 | #include "LevelEditorTest.h" 3 | 4 | using namespace Monocle; 5 | 6 | int main(void) 7 | { 8 | // create a new game instance 9 | Game *game = new Game(); 10 | // set the base content path (used by everything) 11 | Assets::SetContentPath(Assets::GetContentPath() + "/LevelEditorTest/"); 12 | // set the first scene 13 | game->SetScene(new LevelEditorTest::LevelScene()); 14 | // run the main function 15 | game->Main(); 16 | // delete the game 17 | delete game; 18 | return 0; 19 | } 20 | -------------------------------------------------------------------------------- /Samples/Ogmo/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | set(OGMO_SRCS 2 | Main.cpp Ogmo.cpp 3 | ) 4 | 5 | add_executable(TestOgmo ${OGMO_SRCS}) 6 | 7 | target_link_libraries(TestOgmo MonocleCore ${CORE_LINK}) 8 | 9 | -------------------------------------------------------------------------------- /Samples/Ogmo/Main.cpp: -------------------------------------------------------------------------------- 1 | #include "Monocle.h" 2 | #include "Ogmo.h" 3 | 4 | using namespace Monocle; 5 | 6 | int main(void) 7 | { 8 | Game *game = new Game(); 9 | Assets::SetContentPath(Assets::GetContentPath()+"/Ogmo/"); // jw: Why are we doing this, inconsistent. 10 | game->SetScene(new Ogmo::World()); 11 | game->Main(); 12 | delete game; 13 | return 0; 14 | } 15 | -------------------------------------------------------------------------------- /Samples/Ogmo/Ogmo.h: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | 6 | // by @NoelFB 7 | using namespace Monocle; 8 | 9 | namespace Ogmo 10 | { 11 | class Player : public Entity 12 | { 13 | public: 14 | Player(int x, int y); 15 | void Update(); 16 | 17 | Vector2 velocity; 18 | 19 | //details 20 | SpriteAnimation *sprite; 21 | //std::string tag; 22 | 23 | //moving stuff 24 | int const FRICTION_GROUND; 25 | int const FRICTION_AIR; 26 | float const MAXSPEED_GROUND; 27 | float const MAXSPEED_AIR; 28 | int const GRAVITY; 29 | int const JUMP; 30 | int const ACCELERATION; 31 | int const WALLJUMP; 32 | 33 | //double jump / clinging to wall 34 | bool doubleJump; 35 | int cling; 36 | int clingDir; 37 | bool onGround; 38 | bool direction; 39 | 40 | //other/util 41 | bool Motion(float &speed, float &to); 42 | bool CollideAt(const std::string &tag, float x, float y); 43 | 44 | }; 45 | 46 | class Wall : public Entity 47 | { 48 | public: 49 | Wall(int x, int y); 50 | void Render(); 51 | }; 52 | 53 | class Coin : public Entity 54 | { 55 | public: 56 | Coin(int x, int y, Sprite *sprite); 57 | void Update(); 58 | 59 | bool collected; 60 | Vector2 start; 61 | bool reset; 62 | }; 63 | 64 | class Spike : public Entity 65 | { 66 | public: 67 | Spike(int x, int y, Sprite *sprite); 68 | }; 69 | 70 | class World : public Scene 71 | { 72 | public: 73 | void Begin(); 74 | void End(); 75 | void Update(); 76 | static void ResetCoins(); 77 | static World* instance; 78 | 79 | static Player *player; 80 | Wall *wall; 81 | Spike *spike; 82 | Sprite *atCoin; 83 | Sprite *atSpike; 84 | std::list coins; 85 | 86 | }; 87 | } -------------------------------------------------------------------------------- /Samples/Pong/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | set(PONG_SRCS 2 | Main.cpp Pong.cpp 3 | ) 4 | 5 | add_executable(TestPong ${PONG_SRCS}) 6 | 7 | target_link_Libraries(TestPong MonocleCore ${CORE_LINK}) 8 | -------------------------------------------------------------------------------- /Samples/Pong/Main.cpp: -------------------------------------------------------------------------------- 1 | #include "Monocle.h" 2 | #include "Pong.h" 3 | 4 | using namespace Monocle; 5 | 6 | int main(void) 7 | { 8 | Game *game = new Game(); 9 | game->SetScene(new Pong::GameScene()); 10 | game->Main(); 11 | delete game; 12 | return 0; 13 | } 14 | -------------------------------------------------------------------------------- /Samples/Pong/Pong.h: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | using namespace Monocle; 5 | 6 | namespace Pong 7 | { 8 | class Text: public Entity 9 | { 10 | public: 11 | Text(const std::string& text, FontAsset* font); 12 | 13 | void Render(); 14 | 15 | void SetFont(FontAsset* font) { this->font = font; } 16 | void SetText(const std::string& text) { this->text = text; } 17 | 18 | protected: 19 | FontAsset* font; 20 | std::string text; 21 | }; 22 | 23 | class Paddle : public Entity 24 | { 25 | public: 26 | Paddle(); 27 | void Update(); 28 | void Render(); 29 | 30 | KeyCode keyUp; 31 | KeyCode keyDown; 32 | 33 | float speed; 34 | }; 35 | 36 | class Ball : public Entity 37 | { 38 | public: 39 | Ball(); 40 | void Update(); 41 | void Render(); 42 | TextureAsset *texture; 43 | Vector2 velocity; 44 | }; 45 | 46 | class GameScene : public Scene 47 | { 48 | public: 49 | Ball *ball; 50 | Paddle *paddle1, *paddle2; 51 | Text *scoreText; 52 | 53 | int p1Score, p2Score; 54 | 55 | void ResetBall(); 56 | const std::string GetScoreString(); 57 | 58 | void Begin(); 59 | void End(); 60 | void Update(); 61 | }; 62 | } 63 | -------------------------------------------------------------------------------- /Samples/PuppetTest/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | set(PUPPET_SRCS 2 | Main.cpp PuppetTest.cpp 3 | ) 4 | 5 | add_executable(TestPuppet ${PUPPET_SRCS}) 6 | target_link_libraries(TestPuppet MonocleCore ${CORE_LINK}) 7 | 8 | -------------------------------------------------------------------------------- /Samples/PuppetTest/Main.cpp: -------------------------------------------------------------------------------- 1 | #include "Monocle.h" 2 | #include "PuppetTest.h" 3 | 4 | using namespace Monocle; 5 | 6 | int main(void) 7 | { 8 | Game *game = new Game(); 9 | Assets::SetContentPath(Assets::GetContentPath() + "/PuppetTest/"); 10 | game->SetScene(new PuppetTest::TestScene()); 11 | game->Main(); 12 | delete game; 13 | return 0; 14 | } 15 | -------------------------------------------------------------------------------- /Samples/PuppetTest/PuppetTest.cpp: -------------------------------------------------------------------------------- 1 | #include "PuppetTest.h" 2 | #include 3 | 4 | namespace PuppetTest 5 | { 6 | /// TEST SCENE 7 | void TestScene::Begin() 8 | { 9 | Scene::Begin(); 10 | 11 | Graphics::SetBackgroundColor(Color::white); 12 | 13 | Add(puppetEditor = new PuppetEditor()); 14 | } 15 | 16 | void TestScene::Update() 17 | { 18 | Scene::Update(); 19 | } 20 | 21 | void TestScene::End() 22 | { 23 | puppetEditor = NULL; 24 | Scene::End(); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /Samples/PuppetTest/PuppetTest.h: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | using namespace Monocle; 5 | 6 | namespace PuppetTest 7 | { 8 | class TestScene : public Scene 9 | { 10 | public: 11 | void Begin(); 12 | void End(); 13 | 14 | void Update(); 15 | 16 | protected: 17 | PuppetEditor *puppetEditor; 18 | }; 19 | } 20 | -------------------------------------------------------------------------------- /Samples/RenderTests/TextRenderTest.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | 10 | class RectEntity : public Monocle::Entity 11 | { 12 | public: 13 | RectEntity() {} 14 | RectEntity(Monocle::Rect rect) 15 | { 16 | mRect = rect; 17 | } 18 | 19 | void Render() 20 | { 21 | Monocle::Graphics::PushMatrix(); 22 | Monocle::Graphics::SetColor(Monocle::Color::orange); 23 | Monocle::Graphics::Translate( (mRect.bottomRight.x - mRect.topLeft.x) / 2, (mRect.bottomRight.y - mRect.topLeft.y) / 2, 0); 24 | Monocle::Graphics::RenderQuad( mRect.bottomRight.x - mRect.topLeft.x, mRect.bottomRight.y - mRect.topLeft.y ); 25 | Monocle::Graphics::PopMatrix(); 26 | } 27 | 28 | private: 29 | Monocle::Rect mRect; 30 | }; 31 | 32 | class TextRenderTest : public Monocle::Scene 33 | { 34 | public: 35 | void Begin() 36 | { 37 | font = Monocle::Assets::RequestFont("AudioTest/LiberationSans-Regular.ttf", 24); 38 | textToRender = "This is just a test: Hello World"; 39 | rectToRender = RectEntity( Monocle::Rect( Monocle::Vector2(0,0), Monocle::Vector2( font->GetTextWidth(textToRender), font->GetTextHeight(textToRender))) ); 40 | 41 | Add(&rectToRender); 42 | } 43 | 44 | void Render() 45 | { 46 | Monocle::Graphics::PushMatrix(); 47 | //Monocle::Graphics::Translate(50,50,0); 48 | Monocle::Scene::Render(); 49 | 50 | float x,y; 51 | Monocle::Rect verts, texCoords; 52 | 53 | Monocle::Graphics::SetColor(Monocle::Color::yellow); 54 | 55 | glBegin(GL_QUADS); 56 | 57 | for (int i = 0; i < textToRender.size(); i++) 58 | { 59 | char c = textToRender[i]; 60 | if ((c >= 32) && (c < 128)) 61 | { 62 | font->GetGlyphData(c, &x, &y, verts, texCoords); 63 | 64 | glVertex2f(verts.topLeft.x, verts.topLeft.y); 65 | glVertex2f(verts.bottomRight.x, verts.topLeft.y); 66 | glVertex2f(verts.bottomRight.x, verts.bottomRight.y); 67 | glVertex2f(verts.topLeft.x, verts.bottomRight.y); 68 | } 69 | } 70 | 71 | glEnd(); 72 | 73 | Monocle::Graphics::SetColor( Monocle::Color::red ); 74 | //Monocle::Graphics::SetBlend(Monocle::BLEND_ALPHA); 75 | Monocle::Graphics::BindFont(font); 76 | Monocle::Graphics::RenderText( *font, textToRender, 0.f, font->GetTextHeight(textToRender) ); 77 | Monocle::Graphics::PopMatrix(); 78 | } 79 | private: 80 | Monocle::FontAsset *font; 81 | std::string textToRender; 82 | RectEntity rectToRender; 83 | }; 84 | 85 | //int main() 86 | //{ 87 | // Monocle::Game *game = new Monocle::Game(); 88 | // game->SetScene(new TextRenderTest()); 89 | // 90 | // game->Main(); 91 | // return 0; 92 | //} 93 | -------------------------------------------------------------------------------- /Samples/Scripted/Main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main(void) 4 | { 5 | return 0; 6 | } 7 | 8 | 9 | /* 10 | extern "C" 11 | { 12 | #include 13 | #include 14 | #include 15 | }; 16 | 17 | // Test LUA scripting. 18 | 19 | using namespace Monocle; 20 | 21 | 22 | void initLuaState(lua_State **L) 23 | { 24 | lua_pushcfunction(*L, luaopen_io); 25 | lua_call(*L, 0, 0); 26 | 27 | lua_pushcfunction(*L, luaopen_table); 28 | lua_call(*L, 0, 0); 29 | 30 | lua_pushcfunction(*L, luaopen_string); 31 | lua_call(*L, 0, 0); 32 | 33 | lua_pushcfunction(*L, luaopen_math); 34 | lua_call(*L, 0, 0); 35 | } 36 | 37 | int main(void) 38 | { 39 | // run require with module loader code 40 | // run main.lua 41 | 42 | int iErr = 0; 43 | lua_State *L = luaL_newstate(); 44 | 45 | initLuaState(&L); 46 | 47 | if ((iErr = luaL_loadfile (L, std::string(Platform::GetDefaultContentPath()+"/Scripted/main.lua").c_str())) == 0) 48 | { 49 | // Call main... 50 | if ((iErr = lua_pcall (L, 0, LUA_MULTRET, 0)) == 0) 51 | { 52 | // Push the function name onto the stack 53 | lua_pushstring (L, "HelloWorld"); 54 | // Function is located in the Global Table 55 | lua_gettable (L, LUA_GLOBALSINDEX); 56 | lua_pcall (L, 0, 0, 0); 57 | } 58 | else 59 | { 60 | printf("pcall fail\n"); 61 | } 62 | } 63 | else 64 | { 65 | printf("Couldn't load file!\n"); 66 | } 67 | 68 | lua_close(L); 69 | 70 | return 0; 71 | } 72 | */ -------------------------------------------------------------------------------- /Samples/TestSelector/Main.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Main.cpp 3 | // MonocleTests 4 | // 5 | // Created by Josh Whelchel on 5/2/11. 6 | // 7 | 8 | #include "Monocle.h" 9 | #include "AudioTest/AudioTest.h" 10 | #include "Flash/Flash.h" 11 | #include "Jumper/Jumper.h" 12 | #include "LevelEditor/LevelEditorTest.h" 13 | #include "Ogmo/Ogmo.h" 14 | #include "Pong/Pong.h" 15 | #include "PuppetTest/PuppetTest.h" 16 | 17 | using namespace Monocle; 18 | 19 | static Scene *nextScene = NULL; 20 | static std::string newAssetPath = ""; 21 | static Game *pGame = NULL; 22 | 23 | namespace TestSelector 24 | { 25 | class GameScene : public Scene 26 | { 27 | public: 28 | void Begin() 29 | { 30 | AudioTest::Text *scText; 31 | 32 | const char *testNames[] = { 33 | "Audio", 34 | "Flash", 35 | "Jumper", 36 | "Ogmo", 37 | "Level Editor", 38 | "Pong", 39 | "Puppet Test" 40 | }; 41 | 42 | Debug::Log("TestSelector::GameScene::Begin()!"); 43 | 44 | Scene::Begin(); 45 | 46 | FontAsset* font = Assets::RequestFont("AudioTest/LiberationSans-Regular.ttf", 25.0f); 47 | scText = new AudioTest::Text("Please select a test to run:", font); 48 | scText->position = Vector2(50, 50); 49 | Add(scText); 50 | 51 | int y = 100; 52 | for (int i=0;iposition = Vector2(80,y); 55 | Add(scText); 56 | y+= 30; 57 | } 58 | } 59 | 60 | void Update() 61 | { 62 | Scene::Update(); 63 | 64 | nextScene = NULL; 65 | newAssetPath = ""; 66 | 67 | if (Input::IsKeyPressed(KEY_1)) 68 | { 69 | nextScene = new AudioTest::GameScene(); 70 | } 71 | 72 | if (Input::IsKeyPressed(KEY_2)) 73 | { 74 | newAssetPath = "Flash/"; 75 | nextScene = new Flash::TestScene(); 76 | } 77 | 78 | if (Input::IsKeyPressed(KEY_3)) 79 | { 80 | newAssetPath = "Jumper/"; 81 | nextScene = new Jumper::GameScene(); 82 | } 83 | 84 | if (Input::IsKeyPressed(KEY_4)) 85 | { 86 | newAssetPath = "Ogmo/"; 87 | nextScene = new Ogmo::World(); 88 | } 89 | 90 | if (Input::IsKeyPressed(KEY_5)) 91 | { 92 | newAssetPath = "LevelEditorTest/"; 93 | nextScene = new LevelEditorTest::LevelScene(); 94 | } 95 | 96 | if (Input::IsKeyPressed(KEY_6)) 97 | { 98 | nextScene = new Pong::GameScene(); 99 | } 100 | 101 | if (Input::IsKeyPressed(KEY_7)) 102 | { 103 | newAssetPath = "PuppetTest/"; 104 | nextScene = new PuppetTest::TestScene(); 105 | } 106 | 107 | if (nextScene) 108 | { 109 | Assets::SetContentPath(Platform::GetDefaultContentPath() + newAssetPath); 110 | pGame->SetScene(nextScene); 111 | 112 | } 113 | } 114 | }; 115 | }; 116 | 117 | int main(void) 118 | { 119 | pGame = new Game(); 120 | pGame->SetScene(new TestSelector::GameScene()); 121 | pGame->Main(); 122 | delete pGame; 123 | 124 | return 0; 125 | } 126 | 127 | -------------------------------------------------------------------------------- /Samples/TestSelector/premake4-TestSelector.lua: -------------------------------------------------------------------------------- 1 | 2 | function TestSelector_includefiles( name ) 3 | files { "../"..name.."/**.h", "../"..name.."/**.cpp" } 4 | 5 | if name ~= "TestSelector" then 6 | excludes { "../"..name.."/Main.cpp" } 7 | end 8 | 9 | includedirs{ "../"..name } 10 | end 11 | 12 | -- Generic test app premake4 script 13 | project (_OPTIONS["testapp"]) 14 | kind "ConsoleApp" 15 | language "C++" 16 | basedir ( _BUILD_BASE ) 17 | 18 | monocle_os_defines() 19 | monocle_os_includedirs() 20 | monocle_os_links() 21 | 22 | TestSelector_includefiles("AudioTest") 23 | TestSelector_includefiles("Flash") 24 | TestSelector_includefiles("Jumper") 25 | TestSelector_includefiles("LevelEditor") 26 | TestSelector_includefiles("Ogmo") 27 | TestSelector_includefiles("Pong") 28 | TestSelector_includefiles("PuppetTest") 29 | TestSelector_includefiles("TestSelector") 30 | 31 | 32 | configuration "Debug" 33 | defines { "DEBUG" } 34 | flags { "Symbols" } 35 | monocle_build_targetdir( "debug" ) 36 | 37 | configuration "Release" 38 | defines { "NDEBUG" } 39 | flags { "Optimize" } 40 | monocle_build_targetdir( "release" ) -------------------------------------------------------------------------------- /Samples/premake4-test-generic.lua: -------------------------------------------------------------------------------- 1 | -- Generic test app premake4 script 2 | project (_OPTIONS["testapp"]) 3 | kind "ConsoleApp" 4 | language "C++" 5 | basedir ( _BUILD_BASE ) 6 | 7 | monocle_os_defines() 8 | monocle_os_includedirs() 9 | monocle_os_links() 10 | 11 | files { _OPTIONS["testapp"].."/**.h", _OPTIONS["testapp"].."/**.cpp" } 12 | 13 | configuration "Debug" 14 | defines { "DEBUG" } 15 | flags { "Symbols" } 16 | monocle_build_targetdir( "debug" ) 17 | 18 | configuration "Release" 19 | defines { "NDEBUG" } 20 | flags { "Optimize" } 21 | monocle_build_targetdir( "release" ) -------------------------------------------------------------------------------- /Tests/InputHandlerTest/InputHandlerTest.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | 7 | class EntityInputHandler : public Monocle::Entity, public Monocle::Input::EventHandler 8 | { 9 | public: 10 | ~EntityInputHandler() { } 11 | void OnKeyPress() { } 12 | }; 13 | 14 | class InputHandlerTestScene : public Monocle::Scene, public Monocle::Input::EventHandler 15 | { 16 | public: 17 | void Begin() 18 | { 19 | Monocle::Input::AddHandler(this); 20 | Monocle::Input::AddHandler(entity = new EntityInputHandler()); 21 | } 22 | 23 | void OnKeyPress(Monocle::KeyCode key) 24 | { 25 | Monocle::Debug::Log("Key Pressed!"); 26 | 27 | if(key == Monocle::KEY_R) 28 | { 29 | if(entity) 30 | delete entity; 31 | entity = NULL; 32 | } 33 | } 34 | 35 | void OnKeyRelease(Monocle::KeyCode key) 36 | { 37 | Monocle::Debug::Log("Key Released!"); 38 | } 39 | 40 | void OnMousePress(Monocle::Vector2 mousePos, Monocle::MouseButton button) 41 | { 42 | if(button == Monocle::MOUSE_BUTTON_LEFT) 43 | Monocle::Debug::Log("Left Mouse Button pressed!"); 44 | if(button == Monocle::MOUSE_BUTTON_RIGHT) 45 | Monocle::Debug::Log("Right Mouse Button pressed!"); 46 | if(button == Monocle::MOUSE_BUTTON_MIDDLE) 47 | Monocle::Debug::Log("Middle Mouse Button pressed!"); 48 | } 49 | 50 | void OnMouseRelease(Monocle::Vector2 mousePos, Monocle::MouseButton button) 51 | { 52 | if(button == Monocle::MOUSE_BUTTON_LEFT) 53 | Monocle::Debug::Log("Left Mouse Button released!"); 54 | if(button == Monocle::MOUSE_BUTTON_RIGHT) 55 | Monocle::Debug::Log("Right Mouse Button released!"); 56 | if(button == Monocle::MOUSE_BUTTON_MIDDLE) 57 | Monocle::Debug::Log("Middle Mouse Button released!"); 58 | } 59 | 60 | void OnMouseScroll(int scrollDelta) 61 | { 62 | Monocle::Debug::Log("Mouse Scrolled!"); 63 | Monocle::Debug::Log(scrollDelta); 64 | } 65 | 66 | void OnMouseMove(Monocle::Vector2 mousePos) 67 | { 68 | Monocle::Debug::Log("Mouse Moved!"); 69 | Monocle::Debug::Log(mousePos); 70 | } 71 | 72 | private: 73 | EntityInputHandler *entity; 74 | }; 75 | -------------------------------------------------------------------------------- /Tests/InputHandlerTest/Main.cpp: -------------------------------------------------------------------------------- 1 | #include "InputHandlerTest.h" 2 | 3 | #include 4 | 5 | int main() 6 | { 7 | Monocle::Game game("Input Handler Test"); 8 | game.SetScene(new InputHandlerTestScene()); 9 | game.Main(); 10 | 11 | return 0; 12 | } 13 | -------------------------------------------------------------------------------- /Tests/Libraries/cpptest/cpptest-collectoroutput.h: -------------------------------------------------------------------------------- 1 | // --- 2 | // 3 | // $Id: cpptest-collectoroutput.h,v 1.3 2005/06/08 08:08:06 nilu Exp $ 4 | // 5 | // CppTest - A C++ Unit Testing Framework 6 | // Copyright (c) 2003 Niklas Lundell 7 | // 8 | // --- 9 | // 10 | // This library is free software; you can redistribute it and/or 11 | // modify it under the terms of the GNU Lesser General Public 12 | // License as published by the Free Software Foundation; either 13 | // version 2 of the License, or (at your option) any later version. 14 | // 15 | // This library is distributed in the hope that it will be useful, 16 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 17 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 18 | // Lesser General Public License for more details. 19 | // 20 | // You should have received a copy of the GNU Lesser General Public 21 | // License along with this library; if not, write to the 22 | // Free Software Foundation, Inc., 59 Temple Place - Suite 330, 23 | // Boston, MA 02111-1307, USA. 24 | // 25 | // --- 26 | 27 | /** \file */ 28 | 29 | #ifndef CPPTEST_COLLECTOROUTPUT_H 30 | #define CPPTEST_COLLECTOROUTPUT_H 31 | 32 | #include 33 | #include 34 | #include 35 | 36 | #include "cpptest-output.h" 37 | #include "cpptest-source.h" 38 | #include "cpptest-time.h" 39 | 40 | namespace Test 41 | { 42 | /// \brief Collector output. 43 | /// 44 | /// Base class for output handlers that need to report status when all 45 | /// tests have executed. 46 | /// 47 | class CollectorOutput : public Output 48 | { 49 | public: 50 | virtual void finished(int tests, const Time& time); 51 | virtual void suite_start(int tests, const std::string& name); 52 | virtual void suite_end(int tests, const std::string& name, 53 | const Time& time); 54 | virtual void test_start(const std::string& name); 55 | virtual void test_end(const std::string& name, bool ok, 56 | const Time& time); 57 | virtual void assertment(const Source& s); 58 | 59 | protected: 60 | struct OutputSuiteInfo; 61 | struct OutputTestInfo; 62 | struct OutputErrorTestInfo; 63 | 64 | typedef std::list Sources; 65 | 66 | struct TestInfo 67 | { 68 | std::string _name; 69 | Time _time; 70 | 71 | bool _success : 1; 72 | Sources _sources; 73 | 74 | explicit TestInfo(const std::string name); 75 | }; 76 | 77 | typedef std::vector Tests; 78 | 79 | struct SuiteInfo 80 | { 81 | std::string _name; 82 | int _errors; 83 | Tests _tests; 84 | Time _time; 85 | 86 | SuiteInfo(const std::string& name, int tests); 87 | }; 88 | 89 | typedef std::list Suites; 90 | 91 | Suites _suites; 92 | int _total_errors; 93 | int _total_tests; 94 | Time _total_time; 95 | 96 | CollectorOutput(); 97 | 98 | private: 99 | SuiteInfo* _cur_suite; 100 | TestInfo* _cur_test; 101 | }; 102 | 103 | } // namespace Test 104 | 105 | #endif // #ifndef CPPTEST_COLLECTOROUTPUT_H 106 | 107 | -------------------------------------------------------------------------------- /Tests/Libraries/cpptest/cpptest-htmloutput.h: -------------------------------------------------------------------------------- 1 | // --- 2 | // 3 | // $Id: cpptest-htmloutput.h,v 1.3 2005/06/08 08:08:06 nilu Exp $ 4 | // 5 | // CppTest - A C++ Unit Testing Framework 6 | // Copyright (c) 2003 Niklas Lundell 7 | // 8 | // --- 9 | // 10 | // This library is free software; you can redistribute it and/or 11 | // modify it under the terms of the GNU Lesser General Public 12 | // License as published by the Free Software Foundation; either 13 | // version 2 of the License, or (at your option) any later version. 14 | // 15 | // This library is distributed in the hope that it will be useful, 16 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 17 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 18 | // Lesser General Public License for more details. 19 | // 20 | // You should have received a copy of the GNU Lesser General Public 21 | // License along with this library; if not, write to the 22 | // Free Software Foundation, Inc., 59 Temple Place - Suite 330, 23 | // Boston, MA 02111-1307, USA. 24 | // 25 | // --- 26 | 27 | /** \file */ 28 | 29 | #ifndef CPPTEST_HTMLOUTPUT_H 30 | #define CPPTEST_HTMLOUTPUT_H 31 | 32 | #include 33 | #include 34 | 35 | #include "cpptest-collectoroutput.h" 36 | 37 | namespace Test 38 | { 39 | /// \brief HTML output. 40 | /// 41 | /// %Output handler that creates a HTML table with detailed information 42 | /// about all tests. 43 | /// 44 | class HtmlOutput : public CollectorOutput 45 | { 46 | public: 47 | void generate(std::ostream& os, bool incl_ok_tests = true, 48 | const std::string& name = ""); 49 | 50 | private: 51 | struct SuiteRow; 52 | struct TestRow; 53 | struct TestSuiteRow; 54 | struct TestResult; 55 | struct TestResultAll; 56 | struct SuiteTestResult; 57 | 58 | friend struct TestSuiteRow; 59 | }; 60 | 61 | } // namespace Test 62 | 63 | #endif // #ifndef CPPTEST_HTMLOUTPUT_H 64 | 65 | -------------------------------------------------------------------------------- /Tests/Libraries/cpptest/cpptest-source.h: -------------------------------------------------------------------------------- 1 | // --- 2 | // 3 | // $Id: cpptest-source.h,v 1.3 2005/06/08 08:08:06 nilu Exp $ 4 | // 5 | // CppTest - A C++ Unit Testing Framework 6 | // Copyright (c) 2003 Niklas Lundell 7 | // 8 | // --- 9 | // 10 | // This library is free software; you can redistribute it and/or 11 | // modify it under the terms of the GNU Lesser General Public 12 | // License as published by the Free Software Foundation; either 13 | // version 2 of the License, or (at your option) any later version. 14 | // 15 | // This library is distributed in the hope that it will be useful, 16 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 17 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 18 | // Lesser General Public License for more details. 19 | // 20 | // You should have received a copy of the GNU Lesser General Public 21 | // License along with this library; if not, write to the 22 | // Free Software Foundation, Inc., 59 Temple Place - Suite 330, 23 | // Boston, MA 02111-1307, USA. 24 | // 25 | // --- 26 | 27 | /** \file */ 28 | 29 | #ifndef CPPTEST_SOURCE_H 30 | #define CPPTEST_SOURCE_H 31 | 32 | #include 33 | 34 | namespace Test 35 | { 36 | class Suite; 37 | 38 | /// \brief Assertment source information. 39 | /// 40 | /// Contains information about an assertment point. 41 | /// 42 | class Source 43 | { 44 | friend class Suite; 45 | 46 | public: 47 | Source(); 48 | Source(const char* file, unsigned int line, const char* msg); 49 | 50 | const std::string& file() const; 51 | unsigned int line() const; 52 | const std::string& message() const; 53 | const std::string& suite() const; 54 | const std::string& test() const; 55 | 56 | private: 57 | unsigned int _line; 58 | std::string _file; 59 | std::string _msg; 60 | std::string _suite; 61 | std::string _test; 62 | }; 63 | 64 | } // namespace Test 65 | 66 | #endif // #ifndef CPPTEST_SOURCE_H 67 | 68 | -------------------------------------------------------------------------------- /Tests/Libraries/cpptest/cpptest-textoutput.h: -------------------------------------------------------------------------------- 1 | // --- 2 | // 3 | // $Id: cpptest-textoutput.h,v 1.3 2005/06/08 08:08:06 nilu Exp $ 4 | // 5 | // CppTest - A C++ Unit Testing Framework 6 | // Copyright (c) 2003 Niklas Lundell 7 | // 8 | // --- 9 | // 10 | // This library is free software; you can redistribute it and/or 11 | // modify it under the terms of the GNU Lesser General Public 12 | // License as published by the Free Software Foundation; either 13 | // version 2 of the License, or (at your option) any later version. 14 | // 15 | // This library is distributed in the hope that it will be useful, 16 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 17 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 18 | // Lesser General Public License for more details. 19 | // 20 | // You should have received a copy of the GNU Lesser General Public 21 | // License along with this library; if not, write to the 22 | // Free Software Foundation, Inc., 59 Temple Place - Suite 330, 23 | // Boston, MA 02111-1307, USA. 24 | // 25 | // --- 26 | 27 | /** \file */ 28 | 29 | #ifndef CPPTEST_TEXTOUTPUT_H 30 | #define CPPTEST_TEXTOUTPUT_H 31 | 32 | #include 33 | #include 34 | 35 | #include "cpptest-source.h" 36 | #include "cpptest-output.h" 37 | 38 | namespace Test 39 | { 40 | /// \brief Text output handler that outputs to the a stream. 41 | /// 42 | /// %Test suite output handler that writes its information as text to a 43 | /// a stream. It it possible to select between two different operational 44 | /// modes that controls the detail level, see Mode. 45 | /// 46 | class TextOutput : public Output 47 | { 48 | public: 49 | /// Output mode. 50 | /// 51 | enum Mode 52 | { 53 | /// Terse output mode, which only shows the number of correct tests. 54 | /// 55 | Terse, 56 | 57 | /// Verbose output mode, which also shows extended assert 58 | /// information for each test that failed. 59 | /// 60 | Verbose 61 | }; 62 | 63 | TextOutput(Mode mode, std::ostream& stream = std::cout); 64 | 65 | virtual void finished(int tests, const Time& time); 66 | virtual void suite_start(int tests, const std::string& name); 67 | virtual void suite_end(int tests, const std::string& name, 68 | const Time& time); 69 | virtual void test_end(const std::string& name, bool ok, 70 | const Time& time); 71 | virtual void assertment(const Source& s); 72 | 73 | private: 74 | typedef std::list ErrorList; 75 | 76 | Mode _mode; 77 | std::ostream& _stream; 78 | ErrorList _suite_error_list; 79 | std::string _suite_name; 80 | int _suite_errors; 81 | int _suite_tests; 82 | int _suite_total_tests; 83 | int _total_errors; 84 | }; 85 | 86 | } // namespace Test 87 | 88 | #endif // #ifndef CPPTEST_TEXTOUTPUT_H 89 | -------------------------------------------------------------------------------- /Tests/Libraries/cpptest/cpptest-time.h: -------------------------------------------------------------------------------- 1 | // --- 2 | // 3 | // $Id: cpptest-time.h,v 1.3 2005/06/08 08:08:06 nilu Exp $ 4 | // 5 | // CppTest - A C++ Unit Testing Framework 6 | // Copyright (c) 2003 Niklas Lundell 7 | // 8 | // --- 9 | // 10 | // This library is free software; you can redistribute it and/or 11 | // modify it under the terms of the GNU Lesser General Public 12 | // License as published by the Free Software Foundation; either 13 | // version 2 of the License, or (at your option) any later version. 14 | // 15 | // This library is distributed in the hope that it will be useful, 16 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 17 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 18 | // Lesser General Public License for more details. 19 | // 20 | // You should have received a copy of the GNU Lesser General Public 21 | // License along with this library; if not, write to the 22 | // Free Software Foundation, Inc., 59 Temple Place - Suite 330, 23 | // Boston, MA 02111-1307, USA. 24 | // 25 | // --- 26 | 27 | /** \file */ 28 | 29 | #ifndef CPPTEST_TIME_H 30 | #define CPPTEST_TIME_H 31 | 32 | #include 33 | #include 34 | 35 | namespace Test 36 | { 37 | /// \brief %Time representation. 38 | /// 39 | /// Encapsulates a time value with microsecond resolution. It is possible 40 | /// to retrieve the current time, add and subtract time values, and output 41 | /// the time to an output stream. 42 | /// 43 | class Time 44 | { 45 | public: 46 | Time(); 47 | Time(unsigned int sec, unsigned int usec); 48 | 49 | unsigned int seconds() const; 50 | unsigned int microseconds() const; 51 | 52 | static Time current(); 53 | 54 | friend Time operator+(const Time& t1, const Time& t2); 55 | friend Time operator-(const Time& t1, const Time& t2); 56 | 57 | friend std::ostream& operator<<(std::ostream& os, const Time& t); 58 | 59 | private: 60 | unsigned int _sec; 61 | unsigned int _usec; 62 | }; 63 | 64 | } // namespace Test 65 | 66 | #endif // #ifndef CPPTEST_TIME_H 67 | -------------------------------------------------------------------------------- /Tests/Libraries/cpptest/cpptest.h: -------------------------------------------------------------------------------- 1 | // --- 2 | // 3 | // $Id: cpptest.h,v 1.3 2005/06/08 08:08:06 nilu Exp $ 4 | // 5 | // CppTest - A C++ Unit Testing Framework 6 | // Copyright (c) 2003 Niklas Lundell 7 | // 8 | // --- 9 | // 10 | // This library is free software; you can redistribute it and/or 11 | // modify it under the terms of the GNU Lesser General Public 12 | // License as published by the Free Software Foundation; either 13 | // version 2 of the License, or (at your option) any later version. 14 | // 15 | // This library is distributed in the hope that it will be useful, 16 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 17 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 18 | // Lesser General Public License for more details. 19 | // 20 | // You should have received a copy of the GNU Lesser General Public 21 | // License along with this library; if not, write to the 22 | // Free Software Foundation, Inc., 59 Temple Place - Suite 330, 23 | // Boston, MA 02111-1307, USA. 24 | // 25 | // --- 26 | 27 | /** \file */ 28 | 29 | #ifndef CPPTEST_H 30 | #define CPPTEST_H 31 | 32 | #include "cpptest-assert.h" 33 | #include "cpptest-source.h" 34 | #include "cpptest-suite.h" 35 | #include "cpptest-time.h" 36 | 37 | #include "cpptest-compileroutput.h" 38 | #include "cpptest-htmloutput.h" 39 | #include "cpptest-textoutput.h" 40 | 41 | #endif // #ifndef CPPTEST_H 42 | 43 | -------------------------------------------------------------------------------- /Tests/Main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include 4 | #include 5 | 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | 12 | int main() 13 | { 14 | Test::Suite unit; 15 | unit.add(std::auto_ptr< ::Test::Suite>( new Monocle::Test::Unit::Assets())); 16 | unit.add(std::auto_ptr< ::Test::Suite>( new Monocle::Test::Unit::Asset() )); 17 | unit.add(std::auto_ptr< ::Test::Suite>( new Monocle::Test::Unit::FontAsset() )); 18 | unit.add(std::auto_ptr< ::Test::Suite>( new Monocle::Test::Unit::Camera() )); 19 | unit.add(std::auto_ptr< ::Test::Suite>( new Monocle::Test::Unit::Vector() )); 20 | 21 | Test::TextOutput output(Test::TextOutput::Verbose); 22 | unit.run(output, false); 23 | } 24 | -------------------------------------------------------------------------------- /Tests/Tests.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #define CONTENT_PATH "../../../Content/" 4 | -------------------------------------------------------------------------------- /Tests/Unit/AssetTest.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include 4 | #include "AssetTest.h" 5 | 6 | namespace Monocle 7 | { 8 | namespace Test 9 | { 10 | namespace Unit 11 | { 12 | Asset::Asset() 13 | { 14 | TEST_ADD(Asset::Constructor) 15 | TEST_ADD(Asset::ReferenceCount) 16 | //TEST_ADD(Asset::GetName) 17 | //TEST_ADD(Asset::GetExtension) 18 | } 19 | 20 | void Asset::setup() 21 | { 22 | asset = new DerivedAsset(); 23 | } 24 | 25 | void Asset::tear_down() 26 | { 27 | delete asset; 28 | asset = NULL; 29 | } 30 | 31 | void Asset::Constructor() 32 | { 33 | TEST_ASSERT(asset->type == Monocle::ASSET_UNDEFINED); 34 | TEST_ASSERT(asset->referenceCount == 0); 35 | TEST_ASSERT(asset->filename == ""); 36 | } 37 | 38 | void Asset::ReferenceCount() 39 | { 40 | TEST_ASSERT(asset->referenceCount == 0); 41 | asset->AddReference(); 42 | TEST_ASSERT(asset->referenceCount == 1); 43 | asset->AddReference(); 44 | TEST_ASSERT(asset->referenceCount == 2); 45 | asset->RemoveReference(); 46 | TEST_ASSERT(asset->referenceCount == 1); 47 | } 48 | 49 | void Asset::GetName() 50 | { 51 | std::string name = asset->GetName(); 52 | TEST_FAIL(name.data()); 53 | } 54 | 55 | void Asset::GetExtension() 56 | { 57 | std::string ext = asset->GetExtension(); 58 | TEST_FAIL(ext.data()); 59 | } 60 | } 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /Tests/Unit/AssetTest.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | #include 6 | 7 | namespace Monocle 8 | { 9 | class Asset; 10 | 11 | namespace Test 12 | { 13 | namespace Unit 14 | { 15 | class DerivedAsset : public Monocle::Asset 16 | { 17 | public: 18 | DerivedAsset() : Monocle::Asset(Monocle::ASSET_UNDEFINED) {} 19 | 20 | void Unload() {} 21 | void Reload() {} 22 | }; 23 | 24 | class Asset: public ::Test::Suite 25 | { 26 | public: 27 | Asset(); 28 | 29 | protected: 30 | virtual void setup(); 31 | virtual void tear_down(); 32 | 33 | private: 34 | void Constructor(); 35 | void Destructor(); 36 | void ReferenceCount(); 37 | void GetName(); 38 | void GetExtension(); 39 | 40 | Monocle::Asset *asset; 41 | }; 42 | 43 | } 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /Tests/Unit/AssetsTest.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | #include 6 | 7 | namespace Monocle 8 | { 9 | class Game; 10 | class Assets; 11 | 12 | namespace Test 13 | { 14 | namespace Unit 15 | { 16 | class DerivedAssets : public Monocle::Assets 17 | { 18 | public: 19 | DerivedAssets() : Monocle::Assets() {} 20 | 21 | void init(); 22 | 23 | void remove(Asset *asset); 24 | }; 25 | 26 | class Assets: public ::Test::Suite 27 | { 28 | public: 29 | Assets(); 30 | 31 | protected: 32 | virtual void setup(); 33 | virtual void tear_down(); 34 | 35 | private: 36 | void Init(); 37 | void RequestTexture(); 38 | void RequestFont(); 39 | void RequestAudio(); 40 | void GetContentPath(); 41 | 42 | Monocle::Assets *assets; 43 | }; 44 | 45 | } 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /Tests/Unit/CameraTest.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include "CameraTest.h" 4 | #include 5 | 6 | namespace Monocle 7 | { 8 | namespace Test 9 | { 10 | namespace Unit 11 | { 12 | Camera::Camera() 13 | { 14 | TEST_ADD(Camera::Visibility); 15 | TEST_ADD(Camera::VisibleLayers); 16 | } 17 | 18 | void Camera::setup() 19 | { 20 | camera = new Monocle::Camera(); 21 | } 22 | 23 | void Camera::tear_down() 24 | { 25 | delete camera; 26 | } 27 | 28 | void Camera::Visibility() 29 | { 30 | 31 | } 32 | 33 | void Camera::VisibleLayers() 34 | { 35 | camera->SetLayers(10,10); 36 | TEST_ASSERT(camera->GetBackLayer() == 10); 37 | TEST_ASSERT(camera->GetFrontLayer() == 10); 38 | 39 | camera->SetLayers(2,2); 40 | TEST_ASSERT(camera->GetBackLayer() == 2); 41 | TEST_ASSERT(camera->GetFrontLayer() == 2); 42 | } 43 | } 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /Tests/Unit/CameraTest.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | namespace Monocle 6 | { 7 | class Camera; 8 | 9 | namespace Test 10 | { 11 | namespace Unit 12 | { 13 | //Dependencies: Assets, Asset 14 | class Camera: public ::Test::Suite 15 | { 16 | public: 17 | Camera(); 18 | 19 | protected: 20 | virtual void setup(); 21 | virtual void tear_down(); 22 | 23 | private: 24 | void Visibility(); 25 | void VisibleLayers(); 26 | 27 | Monocle::Camera *camera; 28 | }; 29 | 30 | } 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /Tests/Unit/FontAssetTest.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include "FontAssetTest.h" 4 | #include "../Tests.h" 5 | 6 | #include 7 | #include 8 | #include 9 | 10 | #include 11 | #include 12 | 13 | #include 14 | 15 | namespace Monocle 16 | { 17 | namespace Test 18 | { 19 | namespace Unit 20 | { 21 | FontAsset::FontAsset() 22 | { 23 | TEST_ADD(FontAsset::Type) 24 | TEST_ADD(FontAsset::GetGlyphData) 25 | } 26 | 27 | void FontAsset::setup() 28 | { 29 | Game g; 30 | 31 | Monocle::Assets::SetContentPath(CONTENT_PATH); 32 | font = Monocle::Assets::RequestFont("AudioTest/LiberationSans-Regular.ttf", 24); 33 | } 34 | 35 | void FontAsset::tear_down() 36 | { 37 | delete font; 38 | font = NULL; 39 | } 40 | 41 | void FontAsset::Type() 42 | { 43 | TEST_ASSERT(font->type == ASSET_FONT); 44 | } 45 | 46 | void FontAsset::GetGlyphData() 47 | { 48 | for(int c = 32; c < 126; c++) 49 | { 50 | Monocle::Rect glyphbounds, texcoords; 51 | float x,y; 52 | font->GetGlyphData(c, &x, &y, glyphbounds, texcoords); 53 | 54 | //std::cout << "Rect: ( loc: (" << glyphbounds.topLeft.x << "," << glyphbounds.topLeft.y << ") dim: (" << (glyphbounds.bottomRight.x - glyphbounds.topLeft.x) << "," << (glyphbounds.bottomRight.y - glyphbounds.topLeft.y) << ") )" << std::endl; 55 | } 56 | } 57 | } 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /Tests/Unit/FontAssetTest.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | namespace Monocle 6 | { 7 | class FontAsset; 8 | 9 | namespace Test 10 | { 11 | namespace Unit 12 | { 13 | //Dependencies: Assets, Asset 14 | class FontAsset: public ::Test::Suite 15 | { 16 | public: 17 | FontAsset(); 18 | 19 | protected: 20 | virtual void setup(); 21 | virtual void tear_down(); 22 | 23 | private: 24 | void Type(); 25 | void GetGlyphData(); 26 | void GetTextWidth(); 27 | void GetTextHeight(); 28 | 29 | Monocle::FontAsset *font; 30 | }; 31 | 32 | } 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /Tests/Unit/VectorTest.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | namespace Monocle 6 | { 7 | class Vector2; 8 | class Vector3; 9 | 10 | namespace Test 11 | { 12 | namespace Unit 13 | { 14 | //Dependencies: Assets, Asset 15 | class Vector : public ::Test::Suite 16 | { 17 | public: 18 | Vector(); 19 | 20 | protected: 21 | virtual void setup(); 22 | virtual void tear_down(); 23 | 24 | private: 25 | void Vec2Magnitude(); 26 | void Vec2Normalization(); 27 | void Vec2Perpendicular(); 28 | void Vec2Clamp(); 29 | void Vec2Range(); 30 | void Vec2Dot(); 31 | void Vec2Cross(); 32 | void Vec2Reflect(); 33 | void Vec2Angle(); 34 | 35 | Monocle::Vector2 *vec2; 36 | Monocle::Vector3 *vec3; 37 | }; 38 | 39 | } 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /linux-build-basic.sh: -------------------------------------------------------------------------------- 1 | wget http://iweb.dl.sourceforge.net/project/premake/Premake/4.3/premake-4.3-linux.tar.gz 2 | tar -xf premake-4.3-linux.tar.gz 3 | ./premake4 gmake 4 | cd Build/gen-gmake-Monocle 5 | make 6 | -------------------------------------------------------------------------------- /premake4.lua: -------------------------------------------------------------------------------- 1 | --premake4.lua 2 | -- 3 | -- Premake4 solution script 4 | -- Created: Airbash, May/03/2011 5 | -- Example usage: "premake4 --testapp=Pong vs2010" 6 | -- 7 | 8 | -- Required globals for helper script 9 | _MONOCLE_APP_BASE = os.getcwd() --root directory of your project 10 | _MONOCLE_BASE = os.getcwd() --root directory for monocle 11 | 12 | dofile( (_MONOCLE_BASE.."/premake4-helper.lua") ) 13 | 14 | print( _MONOCLE_EXTLIB_BASE ); 15 | 16 | -- 17 | -- Monocle Solution 18 | -- 19 | solution (_MONOCLE_SOLUTION_NAME) 20 | basedir( _BUILD_BASE ) 21 | configurations { "Debug", "Release" } 22 | 23 | --Test Application 24 | if _OPTIONS["testapp"] ~= NIL then 25 | monocle_project_testapp( _OPTIONS["testapp"] ) 26 | end 27 | 28 | -- Monocle Core Library 29 | monocle_project_corelib(); 30 | --------------------------------------------------------------------------------