[Orxonox-commit 931] r5654 - code/branches/resource2/data code/branches/resource2/data/levels code/branches/resource2/data/levels/old code/branches/resource2/data/levels/templates code/branches/resource2/data/lua code/branches/resource2/src/core code/branches/resource2/src/orxonox/gamestates code/branches/resource2/src/orxonox/objects code/branches/resource2/src/orxonox/sound data/branches/media_stripped
rgrieder at orxonox.net
rgrieder at orxonox.net
Mon Aug 17 16:37:10 CEST 2009
Author: rgrieder
Date: 2009-08-17 16:37:10 +0200 (Mon, 17 Aug 2009)
New Revision: 5654
Added:
code/branches/resource2/data/lua/
code/branches/resource2/data/lua/LuaStateInit.lua
code/branches/resource2/data/resources_graphics.oxr
code/branches/resource2/src/core/LuaState.cc
code/branches/resource2/src/core/LuaState.h
data/branches/media_stripped/resources_graphics.oxr
Removed:
code/branches/resource2/data/resources.cfg
code/branches/resource2/src/core/LuaBind.cc
code/branches/resource2/src/core/LuaBind.h
data/branches/media_stripped/resources.cfg
Modified:
code/branches/resource2/data/levels/empty_level.oxw
code/branches/resource2/data/levels/gametype_asteroids.oxw
code/branches/resource2/data/levels/gametype_underattack.oxw
code/branches/resource2/data/levels/old/CuboidSpaceStation.oxw
code/branches/resource2/data/levels/old/physicstest2.oxw
code/branches/resource2/data/levels/old/planettest.oxw
code/branches/resource2/data/levels/old/presentation_physics.oxw
code/branches/resource2/data/levels/old/princessaeryn.oxw
code/branches/resource2/data/levels/old/questsystem.oxw
code/branches/resource2/data/levels/old/sample4.oxw
code/branches/resource2/data/levels/pickuptest.oxw
code/branches/resource2/data/levels/presentation.oxw
code/branches/resource2/data/levels/presentation09.oxw
code/branches/resource2/data/levels/presentation09b.oxw
code/branches/resource2/data/levels/presentation_dm.oxw
code/branches/resource2/data/levels/presentation_pong.oxw
code/branches/resource2/data/levels/teambasematchlevel.oxw
code/branches/resource2/data/levels/teamdeathmatch.oxw
code/branches/resource2/data/levels/templates/spaceship_H2.oxt
code/branches/resource2/data/levels/templates/spaceship_assff.oxt
code/branches/resource2/data/levels/templates/spaceship_pirate.oxt
code/branches/resource2/data/levels/tutorial.oxw
code/branches/resource2/data/levels/waypoints.oxw
code/branches/resource2/data/resources.oxr
code/branches/resource2/src/core/CMakeLists.txt
code/branches/resource2/src/core/Core.cc
code/branches/resource2/src/core/Core.h
code/branches/resource2/src/core/CorePrereqs.h
code/branches/resource2/src/core/GUIManager.cc
code/branches/resource2/src/core/GraphicsManager.cc
code/branches/resource2/src/core/GraphicsManager.h
code/branches/resource2/src/core/Loader.cc
code/branches/resource2/src/core/Loader.h
code/branches/resource2/src/orxonox/gamestates/GSGraphics.cc
code/branches/resource2/src/orxonox/gamestates/GSLevel.cc
code/branches/resource2/src/orxonox/gamestates/GSRoot.cc
code/branches/resource2/src/orxonox/objects/Level.cc
code/branches/resource2/src/orxonox/objects/Script.cc
code/branches/resource2/src/orxonox/objects/Script.h
code/branches/resource2/src/orxonox/sound/SoundBase.cc
code/branches/resource2/src/orxonox/sound/SoundBase.h
data/branches/media_stripped/resources.oxr
Log:
- Implemented file management via resource manager and loading of resource locations via XML. Changes made:
- SoundManager loads via memory stream rather than via file
- Loader uses LuaState::includeFile() to load an XML file and passes the lua tag remover function to its LuaState.
- ConfigFileManager still loads with hard paths because the files are required before Ogre gets created
- Renamed LuaBind to LuaState, deSingletonised it and added new features:
- doFile(), doString(), includeFile(), includeString() where include will preparse the string with a function provided with LuaState::setIncludeParser
- Moved lua tags replace function to Loader (since it's actually an XML related task)
- Using data_path/lua/LuaInitScript.lua to provide the following functions
- logMessage(level, message)
- doFile, dofile, include (all working with relative paths but within the same resource group)
- Modified Script class to work with LuaState and fixed its XML Loader
- Adjusted all level and include files (both "include" and "dofile" lua commands)
Modified: code/branches/resource2/data/levels/empty_level.oxw
===================================================================
--- code/branches/resource2/data/levels/empty_level.oxw 2009-08-17 13:42:39 UTC (rev 5653)
+++ code/branches/resource2/data/levels/empty_level.oxw 2009-08-17 14:37:10 UTC (rev 5654)
@@ -1,11 +1,11 @@
<?lua
- include("overlay/stats.oxo")
- include("overlay/hudtemplates3.oxo")
+ include("stats.oxo")
+ include("hudtemplates3.oxo")
?>
<?lua
- include("levels/templates/spaceship_assff.oxt")
- include("levels/templates/spaceship_pirate.oxt")
+ include("templates/spaceship_assff.oxt")
+ include("templates/spaceship_pirate.oxt")
?>
<Level
Modified: code/branches/resource2/data/levels/gametype_asteroids.oxw
===================================================================
--- code/branches/resource2/data/levels/gametype_asteroids.oxw 2009-08-17 13:42:39 UTC (rev 5653)
+++ code/branches/resource2/data/levels/gametype_asteroids.oxw 2009-08-17 14:37:10 UTC (rev 5654)
@@ -1,7 +1,7 @@
<?lua
- include("overlay/hudtemplates3.oxo")
- include("overlay/stats.oxo")
- include("levels/templates/spaceship_assff.oxt")
+ include("hudtemplates3.oxo")
+ include("stats.oxo")
+ include("templates/spaceship_assff.oxt")
?>
<Level
Modified: code/branches/resource2/data/levels/gametype_underattack.oxw
===================================================================
--- code/branches/resource2/data/levels/gametype_underattack.oxw 2009-08-17 13:42:39 UTC (rev 5653)
+++ code/branches/resource2/data/levels/gametype_underattack.oxw 2009-08-17 14:37:10 UTC (rev 5654)
@@ -1,8 +1,8 @@
<?lua
- include("overlay/hudtemplates3.oxo")
- include("overlay/stats.oxo")
- include("overlay/underattackhud.oxo")
- include("levels/templates/spaceship_assff.oxt")
+ include("hudtemplates3.oxo")
+ include("stats.oxo")
+ include("underattackhud.oxo")
+ include("templates/spaceship_assff.oxt")
?>
<Level
Modified: code/branches/resource2/data/levels/old/CuboidSpaceStation.oxw
===================================================================
--- code/branches/resource2/data/levels/old/CuboidSpaceStation.oxw 2009-08-17 13:42:39 UTC (rev 5653)
+++ code/branches/resource2/data/levels/old/CuboidSpaceStation.oxw 2009-08-17 14:37:10 UTC (rev 5654)
@@ -1,9 +1,9 @@
<?lua
- include("overlay/hudtemplates3.oxo")
+ include("hudtemplates3.oxo")
?>
<?lua
- include("levels/templates/spaceship_assff.oxt")
+ include("templates/spaceship_assff.oxt")
?>
<Level
@@ -19,7 +19,7 @@
<!-------------------------------------------------------------------------------------------------------------------------------------------------------------------------->
<?lua
- dofile("../../media/levels/includes/CuboidSpaceStation.lua")
+ dofile("includes/CuboidSpaceStation.lua")
?>
<!-- The following examples insert some space station in various ways, so I guess you will understand how to use my .lua file and the functions of it.
Modified: code/branches/resource2/data/levels/old/physicstest2.oxw
===================================================================
--- code/branches/resource2/data/levels/old/physicstest2.oxw 2009-08-17 13:42:39 UTC (rev 5653)
+++ code/branches/resource2/data/levels/old/physicstest2.oxw 2009-08-17 14:37:10 UTC (rev 5654)
@@ -1,8 +1,8 @@
<?lua
- include("levels/old/spaceshiptemplates_physics.oxw")
+ include("spaceshiptemplates_physics.oxw")
?>
<?lua
- include("overlay/hudtemplates3.oxo")
+ include("hudtemplates3.oxo")
?>
<Level
Modified: code/branches/resource2/data/levels/old/planettest.oxw
===================================================================
--- code/branches/resource2/data/levels/old/planettest.oxw 2009-08-17 13:42:39 UTC (rev 5653)
+++ code/branches/resource2/data/levels/old/planettest.oxw 2009-08-17 14:37:10 UTC (rev 5654)
@@ -1,9 +1,9 @@
<?lua
- include("overlay/hudtemplates3.oxo")
+ include("hudtemplates3.oxo")
?>
<?lua
- include("levels/templates/spaceship_assff.oxt")
+ include("templates/spaceship_assff.oxt")
?>
<Level
Modified: code/branches/resource2/data/levels/old/presentation_physics.oxw
===================================================================
--- code/branches/resource2/data/levels/old/presentation_physics.oxw 2009-08-17 13:42:39 UTC (rev 5653)
+++ code/branches/resource2/data/levels/old/presentation_physics.oxw 2009-08-17 14:37:10 UTC (rev 5654)
@@ -1,7 +1,7 @@
<?lua
- include("overlay/hudtemplates3.oxo")
- include("overlay/stats.oxo")
- include("levels/templates/spaceship_assff.oxt")
+ include("hudtemplates3.oxo")
+ include("stats.oxo")
+ include("templates/spaceship_assff.oxt")
math.randomseed(344)
?>
Modified: code/branches/resource2/data/levels/old/princessaeryn.oxw
===================================================================
--- code/branches/resource2/data/levels/old/princessaeryn.oxw 2009-08-17 13:42:39 UTC (rev 5653)
+++ code/branches/resource2/data/levels/old/princessaeryn.oxw 2009-08-17 14:37:10 UTC (rev 5654)
@@ -1,11 +1,11 @@
<?lua
- include("overlay/hudtemplates3.oxo")
- include("overlay/stats.oxo")
- include("levels/templates/spaceship_assff.oxt")
+ include("hudtemplates3.oxo")
+ include("stats.oxo")
+ include("templates/spaceship_assff.oxt")
?>
<?lua
- dofile("../../media/levels/includes/CuboidSpaceStation.lua")
+ dofile("includes/CuboidSpaceStation.lua")
?>
<NotificationQueue
Modified: code/branches/resource2/data/levels/old/questsystem.oxw
===================================================================
--- code/branches/resource2/data/levels/old/questsystem.oxw 2009-08-17 13:42:39 UTC (rev 5653)
+++ code/branches/resource2/data/levels/old/questsystem.oxw 2009-08-17 14:37:10 UTC (rev 5654)
@@ -1,7 +1,7 @@
<?lua
- include("overlay/hudtemplates3.oxo")
- include("overlay/stats.oxo")
- include("levels/templates/spaceship_assff.oxt")
+ include("hudtemplates3.oxo")
+ include("stats.oxo")
+ include("templates/spaceship_assff.oxt")
?>
<NotificationQueue
Modified: code/branches/resource2/data/levels/old/sample4.oxw
===================================================================
--- code/branches/resource2/data/levels/old/sample4.oxw 2009-08-17 13:42:39 UTC (rev 5653)
+++ code/branches/resource2/data/levels/old/sample4.oxw 2009-08-17 14:37:10 UTC (rev 5654)
@@ -1,9 +1,9 @@
<?lua
- include("overlay/hudtemplates3.oxo")
+ include("hudtemplates3.oxo")
?>
<?lua
- include("levels/templates/spaceship_assff.oxt")
+ include("templates/spaceship_assff.oxt")
?>
<Level
Modified: code/branches/resource2/data/levels/pickuptest.oxw
===================================================================
--- code/branches/resource2/data/levels/pickuptest.oxw 2009-08-17 13:42:39 UTC (rev 5653)
+++ code/branches/resource2/data/levels/pickuptest.oxw 2009-08-17 14:37:10 UTC (rev 5654)
@@ -1,7 +1,7 @@
<?lua
- include("overlay/hudtemplates3.oxo")
- include("overlay/stats.oxo")
- include("levels/templates/spaceship_assff.oxt")
+ include("hudtemplates3.oxo")
+ include("stats.oxo")
+ include("templates/spaceship_assff.oxt")
?>
<Level
Modified: code/branches/resource2/data/levels/presentation.oxw
===================================================================
--- code/branches/resource2/data/levels/presentation.oxw 2009-08-17 13:42:39 UTC (rev 5653)
+++ code/branches/resource2/data/levels/presentation.oxw 2009-08-17 14:37:10 UTC (rev 5654)
@@ -1,7 +1,7 @@
<?lua
- include("overlay/hudtemplates3.oxo")
- include("overlay/stats.oxo")
- include("levels/templates/spaceship_assff.oxt")
+ include("hudtemplates3.oxo")
+ include("stats.oxo")
+ include("templates/spaceship_assff.oxt")
?>
<Level
Modified: code/branches/resource2/data/levels/presentation09.oxw
===================================================================
--- code/branches/resource2/data/levels/presentation09.oxw 2009-08-17 13:42:39 UTC (rev 5653)
+++ code/branches/resource2/data/levels/presentation09.oxw 2009-08-17 14:37:10 UTC (rev 5654)
@@ -1,8 +1,8 @@
<?lua
- include("overlay/hudtemplates3.oxo")
- include("overlay/stats.oxo")
- include("levels/templates/spaceship_assff.oxt")
- include("levels/templates/spaceship_H2.oxt")
+ include("hudtemplates3.oxo")
+ include("stats.oxo")
+ include("templates/spaceship_assff.oxt")
+ include("templates/spaceship_H2.oxt")
?>
<Level
Modified: code/branches/resource2/data/levels/presentation09b.oxw
===================================================================
--- code/branches/resource2/data/levels/presentation09b.oxw 2009-08-17 13:42:39 UTC (rev 5653)
+++ code/branches/resource2/data/levels/presentation09b.oxw 2009-08-17 14:37:10 UTC (rev 5654)
@@ -1,9 +1,9 @@
<?lua
- include("overlay/hudtemplates3.oxo")
- include("overlay/stats.oxo")
- include("levels/templates/spaceship_assff.oxt")
- include("levels/templates/spaceship_H2.oxt")
- include("levels/templates/spaceship_pirate.oxt")
+ include("hudtemplates3.oxo")
+ include("stats.oxo")
+ include("templates/spaceship_assff.oxt")
+ include("templates/spaceship_H2.oxt")
+ include("templates/spaceship_pirate.oxt")
?>
<Level
Modified: code/branches/resource2/data/levels/presentation_dm.oxw
===================================================================
--- code/branches/resource2/data/levels/presentation_dm.oxw 2009-08-17 13:42:39 UTC (rev 5653)
+++ code/branches/resource2/data/levels/presentation_dm.oxw 2009-08-17 14:37:10 UTC (rev 5654)
@@ -1,8 +1,8 @@
<?lua
- include("overlay/hudtemplates3.oxo")
- include("overlay/stats.oxo")
- include("levels/templates/spaceship_assff.oxt")
- include("levels/templates/spaceship_H2.oxt")
+ include("hudtemplates3.oxo")
+ include("stats.oxo")
+ include("templates/spaceship_assff.oxt")
+ include("templates/spaceship_H2.oxt")
?>
<Level
Modified: code/branches/resource2/data/levels/presentation_pong.oxw
===================================================================
--- code/branches/resource2/data/levels/presentation_pong.oxw 2009-08-17 13:42:39 UTC (rev 5653)
+++ code/branches/resource2/data/levels/presentation_pong.oxw 2009-08-17 14:37:10 UTC (rev 5654)
@@ -1,7 +1,7 @@
<?lua
- include("overlay/hudtemplates3.oxo")
- include("overlay/stats.oxo")
- include("overlay/ponghud.oxo")
+ include("hudtemplates3.oxo")
+ include("stats.oxo")
+ include("ponghud.oxo")
?>
<Template name=pongbatcameras defaults=0>
@@ -90,7 +90,7 @@
</EventDispatcher>
<?lua
- dofile("../../media/levels/includes/CuboidSpaceStation.lua")
+ dofile("includes/CuboidSpaceStation.lua")
?>
<StaticEntity pitch=15>
Modified: code/branches/resource2/data/levels/teambasematchlevel.oxw
===================================================================
--- code/branches/resource2/data/levels/teambasematchlevel.oxw 2009-08-17 13:42:39 UTC (rev 5653)
+++ code/branches/resource2/data/levels/teambasematchlevel.oxw 2009-08-17 14:37:10 UTC (rev 5654)
@@ -1,9 +1,9 @@
<?lua
- include("overlay/hudtemplates3.oxo")
- include("overlay/stats.oxo")
- include("overlay/teambasematchhud.oxo")
- include("levels/templates/spaceship_assff.oxt")
- include("levels/templates/spaceship_pirate.oxt")
+ include("hudtemplates3.oxo")
+ include("stats.oxo")
+ include("teambasematchhud.oxo")
+ include("templates/spaceship_assff.oxt")
+ include("templates/spaceship_pirate.oxt")
?>
<Level
Modified: code/branches/resource2/data/levels/teamdeathmatch.oxw
===================================================================
--- code/branches/resource2/data/levels/teamdeathmatch.oxw 2009-08-17 13:42:39 UTC (rev 5653)
+++ code/branches/resource2/data/levels/teamdeathmatch.oxw 2009-08-17 14:37:10 UTC (rev 5654)
@@ -1,9 +1,9 @@
<?lua
- include("overlay/hudtemplates3.oxo")
- include("overlay/stats.oxo")
- include("levels/templates/spaceship_assff.oxt")
- include("levels/templates/spaceship_H2.oxt")
- include("levels/templates/spaceship_pirate.oxt")
+ include("hudtemplates3.oxo")
+ include("stats.oxo")
+ include("templates/spaceship_assff.oxt")
+ include("templates/spaceship_H2.oxt")
+ include("templates/spaceship_pirate.oxt")
?>
<Level
Modified: code/branches/resource2/data/levels/templates/spaceship_H2.oxt
===================================================================
--- code/branches/resource2/data/levels/templates/spaceship_H2.oxt 2009-08-17 13:42:39 UTC (rev 5653)
+++ code/branches/resource2/data/levels/templates/spaceship_H2.oxt 2009-08-17 14:37:10 UTC (rev 5654)
@@ -22,7 +22,7 @@
>
<?lua
- include("levels/includes/weaponsettings_H2.oxi")
+ include("includes/weaponsettings_H2.oxi")
?>
<attached>
Modified: code/branches/resource2/data/levels/templates/spaceship_assff.oxt
===================================================================
--- code/branches/resource2/data/levels/templates/spaceship_assff.oxt 2009-08-17 13:42:39 UTC (rev 5653)
+++ code/branches/resource2/data/levels/templates/spaceship_assff.oxt 2009-08-17 14:37:10 UTC (rev 5654)
@@ -34,7 +34,7 @@
<BoxCollisionShape position="0,0.1,-19" halfExtents="1.4, 1, 2" />
</collisionShapes>
<?lua
- include("levels/includes/weaponsettings3.oxi")
+ include("includes/weaponsettings3.oxi")
?>
</SpaceShip>
</Template>
Modified: code/branches/resource2/data/levels/templates/spaceship_pirate.oxt
===================================================================
--- code/branches/resource2/data/levels/templates/spaceship_pirate.oxt 2009-08-17 13:42:39 UTC (rev 5653)
+++ code/branches/resource2/data/levels/templates/spaceship_pirate.oxt 2009-08-17 14:37:10 UTC (rev 5654)
@@ -37,7 +37,7 @@
</collisionShapes>
<?lua
- include("levels/includes/weaponsettings_pirate.oxi")
+ include("includes/weaponsettings_pirate.oxi")
?>
</SpaceShip>
</Template>
Modified: code/branches/resource2/data/levels/tutorial.oxw
===================================================================
--- code/branches/resource2/data/levels/tutorial.oxw 2009-08-17 13:42:39 UTC (rev 5653)
+++ code/branches/resource2/data/levels/tutorial.oxw 2009-08-17 14:37:10 UTC (rev 5654)
@@ -1,7 +1,7 @@
<?lua
- include("overlay/hudtemplates3.oxo")
- include("overlay/stats.oxo")
- include("levels/templates/spaceship_assff.oxt")
+ include("hudtemplates3.oxo")
+ include("stats.oxo")
+ include("templates/spaceship_assff.oxt")
?>
<Level
Modified: code/branches/resource2/data/levels/waypoints.oxw
===================================================================
--- code/branches/resource2/data/levels/waypoints.oxw 2009-08-17 13:42:39 UTC (rev 5653)
+++ code/branches/resource2/data/levels/waypoints.oxw 2009-08-17 14:37:10 UTC (rev 5654)
@@ -1,9 +1,9 @@
<?lua
- include("overlay/hudtemplates3.oxo")
- include("overlay/stats.oxo")
- include("levels/templates/spaceship_assff.oxt")
- include("levels/templates/spaceship_H2.oxt")
- include("levels/templates/spaceship_pirate.oxt")
+ include("hudtemplates3.oxo")
+ include("stats.oxo")
+ include("templates/spaceship_assff.oxt")
+ include("templates/spaceship_H2.oxt")
+ include("templates/spaceship_pirate.oxt")
?>
<Level
Added: code/branches/resource2/data/lua/LuaStateInit.lua
===================================================================
--- code/branches/resource2/data/lua/LuaStateInit.lua (rev 0)
+++ code/branches/resource2/data/lua/LuaStateInit.lua 2009-08-17 14:37:10 UTC (rev 5654)
@@ -0,0 +1,35 @@
+-- Note: luaState is a pointer to the LuaState instance that created this lua state
+
+-- Redirect debug to print
+debug = print
+
+-- Redirect print to the C++ print function
+print = function(s)
+ luaState:luaPrint(s)
+end
+
+-- Create function to log text like COUT, but always prints a line!
+logMessage = function(level, message)
+ luaState:luaLog(level, message)
+end
+
+-- Redirect dofile in order to load with the resource manager
+-- Note: The function does not behave exactly like LuaState::doFile because the
+-- default argument here for the group is not "General" but
+-- "NoResourceGroupProvided". This resolves to the resource group used to
+-- do the current file.
+doFile = function(filename, resourceGroup)
+ local bSearchOtherPaths = (resourceGroup == nil) or false
+ resourceGroup = resourceGroup or "NoResourceGroupProvided"
+ luaState:doFile(filename, resourceGroup, bSearchOtherPaths)
+end
+dofile = doFile
+
+-- Create includeFile function that preparses the file according
+-- to a function provided to the LuaState constructor (in C++)
+-- Note: See the same notes as for doFile
+include = function(filename, resourceGroup)
+ local bSearchOtherPaths = (resourceGroup == nil) or false
+ resourceGroup = resourceGroup or "NoResourceGroupProvided"
+ luaState:includeFile(filename, resourceGroup, bSearchOtherPaths)
+end
Property changes on: code/branches/resource2/data/lua/LuaStateInit.lua
___________________________________________________________________
Added: svn:eol-style
+ native
Deleted: code/branches/resource2/data/resources.cfg
===================================================================
--- code/branches/resource2/data/resources.cfg 2009-08-17 13:42:39 UTC (rev 5653)
+++ code/branches/resource2/data/resources.cfg 2009-08-17 14:37:10 UTC (rev 5654)
@@ -1,34 +0,0 @@
-# Resource locations to be added to the 'boostrap' path
-# This also contains the minimum you need to use the Ogre example framework
-[Bootstrap]
-Zip=packs/OgreCore.zip
-
-# Resource locations to be added to the default path
-[General]
-FileSystem=.
-FileSystem=fonts
-FileSystem=materials/programs
-FileSystem=materials/scripts
-FileSystem=materials/textures
-FileSystem=models
-FileSystem=overlay
-FileSystem=particle
-#FileSystem=../Media/levels
-#FileSystem=../Media/audio
-Zip=packs/cubemap.zip
-#Zip=../Media/packs/cubemapsJS.zip
-#Zip=../Media/packs/dragon.zip
-#Zip=../Media/packs/fresneldemo.zip
-#Zip=../Media/packs/ogretestmap.zip
-Zip=packs/skybox.zip
-FileSystem=gui/fonts
-
-# CEGUI files
-[GUI]
-FileSystem=gui/configs
-FileSystem=gui/fonts
-FileSystem=gui/imagesets
-FileSystem=gui/layouts
-FileSystem=gui/looknfeel
-FileSystem=gui/schemes
-FileSystem=gui/scripts
Modified: code/branches/resource2/data/resources.oxr
===================================================================
--- code/branches/resource2/data/resources.oxr 2009-08-17 13:42:39 UTC (rev 5653)
+++ code/branches/resource2/data/resources.oxr 2009-08-17 14:37:10 UTC (rev 5654)
@@ -1,19 +1,6 @@
-<ResourceGroup name = "General" >
- <ResourceLocation path = overlay />
- <ResourceLocation path = particle />
- <ResourceLocation path = defaultConfig />
- <ResourceLocation path = levels />
- <ResourceLocation path = tcl />
- <ResourceLocation
- path = test.zip
- archive = Zip
- recursive = true
- />
-</ResourceGroup>
-
-<ResourceGroup name = "GUI" >
- <ResourceLocation path = gui/configs />
- <ResourceLocation path = gui/layouts />
- <ResourceLocation path = gui/schemas />
- <ResourceLocation path = gui/scripts />
-</ResourceGroup>
+<ResourceCollection resourceGroup = "General" >
+ <ResourceLocation path = "levels" />
+ <ResourceLocation path = "lua" />
+ <ResourceLocation path = "overlay" />
+ <ResourceLocation path = "tcl" />
+</ResourceCollection>
Copied: code/branches/resource2/data/resources_graphics.oxr (from rev 5646, code/branches/resource2/data/resources.oxr)
===================================================================
--- code/branches/resource2/data/resources_graphics.oxr (rev 0)
+++ code/branches/resource2/data/resources_graphics.oxr 2009-08-17 14:37:10 UTC (rev 5654)
@@ -0,0 +1,10 @@
+<ResourceCollection resourceGroup = "General" >
+ <ResourceLocation path = "particle" />
+</ResourceCollection>
+
+<ResourceCollection resourceGroup = "GUI" >
+ <ResourceLocation path = "gui/configs" />
+ <ResourceLocation path = "gui/layouts" />
+ <ResourceLocation path = "gui/schemes" />
+ <ResourceLocation path = "gui/scripts" />
+</ResourceCollection>
Modified: code/branches/resource2/src/core/CMakeLists.txt
===================================================================
--- code/branches/resource2/src/core/CMakeLists.txt 2009-08-17 13:42:39 UTC (rev 5653)
+++ code/branches/resource2/src/core/CMakeLists.txt 2009-08-17 14:37:10 UTC (rev 5654)
@@ -29,7 +29,7 @@
GraphicsManager.cc
GUIManager.cc
Language.cc
- LuaBind.cc
+ LuaState.cc
ObjectListBase.cc
OrxonoxClass.cc
Resource.cc
@@ -75,7 +75,8 @@
FIND_HEADER_FILES
TOLUA_FILES
CommandExecutor.h
- LuaBind.h
+ Loader.h
+ LuaState.h
DEFINE_SYMBOL
"CORE_SHARED_BUILD"
PCH_FILE
Modified: code/branches/resource2/src/core/Core.cc
===================================================================
--- code/branches/resource2/src/core/Core.cc 2009-08-17 13:42:39 UTC (rev 5653)
+++ code/branches/resource2/src/core/Core.cc 2009-08-17 14:37:10 UTC (rev 5654)
@@ -73,10 +73,11 @@
#include "GUIManager.h"
#include "Identifier.h"
#include "Language.h"
-#include "LuaBind.h"
+#include "LuaState.h"
#include "Shell.h"
#include "TclBind.h"
#include "TclThreadManager.h"
+#include "ToluaBindCore.h"
#include "input/InputManager.h"
namespace orxonox
@@ -265,6 +266,8 @@
if (limitToCPU > 0)
setThreadAffinity(static_cast<unsigned int>(limitToCPU));
#endif
+ // Add tolua interface
+ LuaState::addToluaInterface(&tolua_Core_open, "Core");
// Manage ini files and set the default settings file (usually orxonox.ini)
this->configFileManager_.reset(new ConfigFileManager());
@@ -274,12 +277,15 @@
// Required as well for the config values
this->languageInstance_.reset(new Language());
+ // creates the class hierarchy for all classes with factories
+ Factory::createClassHierarchy();
+
// Do this soon after the ConfigFileManager has been created to open up the
// possibility to configure everything below here
this->configuration_->initialise();
- // Create the lua interface
- this->luaBind_.reset(new LuaBind());
+ // Load OGRE excluding the renderer and the render window
+ this->graphicsManager_.reset(new GraphicsManager(false));
// initialise Tcl
this->tclBind_.reset(new TclBind(Core::getDataPathString()));
@@ -287,17 +293,11 @@
// create a shell
this->shell_.reset(new Shell());
-
- // creates the class hierarchy for all classes with factories
- Factory::createClassHierarchy();
-
- // Load OGRE excluding the renderer and the render window
- this->graphicsManager_.reset(new GraphicsManager(false));
}
/**
@brief
- All destruction code is handled by scoped_ptrs and SimpleScopeGuards.
+ All destruction code is handled by scoped_ptrs and ScopeGuards.
*/
Core::~Core()
{
@@ -560,7 +560,7 @@
{
COUT(1) << "Running from the build tree." << std::endl;
Core::bDevRun_ = true;
- configuration_->dataPath_ = specialConfig::dataDevDirectory;
+ configuration_->dataPath_ = specialConfig::dataDevDirectory;
configuration_->externalDataPath_ = specialConfig::externalDataDevDirectory;
configuration_->configPath_ = specialConfig::configDevDirectory;
configuration_->logPath_ = specialConfig::logDevDirectory;
@@ -578,7 +578,7 @@
ThrowException(General, "Could not derive a root directory. Might the binary installation directory contain '..' when taken relative to the installation prefix path?");
// Using paths relative to the install prefix, complete them
- configuration_->dataPath_ = configuration_->rootPath_ / specialConfig::defaultDataPath;
+ configuration_->dataPath_ = configuration_->rootPath_ / specialConfig::defaultDataPath;
configuration_->configPath_ = configuration_->rootPath_ / specialConfig::defaultConfigPath;
configuration_->logPath_ = configuration_->rootPath_ / specialConfig::defaultLogPath;
#else
Modified: code/branches/resource2/src/core/Core.h
===================================================================
--- code/branches/resource2/src/core/Core.h 2009-08-17 13:42:39 UTC (rev 5653)
+++ code/branches/resource2/src/core/Core.h 2009-08-17 14:37:10 UTC (rev 5654)
@@ -128,7 +128,6 @@
scoped_ptr<ConfigFileManager> configFileManager_;
scoped_ptr<Language> languageInstance_;
scoped_ptr<CoreConfiguration> configuration_;
- scoped_ptr<LuaBind> luaBind_;
scoped_ptr<TclBind> tclBind_;
scoped_ptr<TclThreadManager> tclThreadManager_;
scoped_ptr<Shell> shell_;
Modified: code/branches/resource2/src/core/CorePrereqs.h
===================================================================
--- code/branches/resource2/src/core/CorePrereqs.h 2009-08-17 13:42:39 UTC (rev 5653)
+++ code/branches/resource2/src/core/CorePrereqs.h 2009-08-17 14:37:10 UTC (rev 5654)
@@ -132,7 +132,7 @@
class Language;
class LanguageEntry;
class Loader;
- class LuaBind;
+ class LuaState;
class MetaObjectList;
class MetaObjectListElement;
class Namespace;
Modified: code/branches/resource2/src/core/GUIManager.cc
===================================================================
--- code/branches/resource2/src/core/GUIManager.cc 2009-08-17 13:42:39 UTC (rev 5653)
+++ code/branches/resource2/src/core/GUIManager.cc 2009-08-17 14:37:10 UTC (rev 5654)
@@ -58,7 +58,7 @@
#include "util/OrxAssert.h"
#include "Core.h"
#include "Clock.h"
-#include "LuaBind.h"
+#include "LuaState.h"
namespace orxonox
{
@@ -131,7 +131,7 @@
guiSystem_.reset(new System(guiRenderer_.get(), resourceProvider_, 0, scriptModule_.get()));
// do this after 'new CEGUI::Sytem' because that creates the lua state in the first place
- LuaBind::getInstance().openToluaInterfaces(this->luaState_);
+ LuaState::openToluaInterfaces(this->luaState_);
// initialise the basic lua code
this->loadLuaCode();
@@ -156,7 +156,7 @@
GUIManager::~GUIManager()
{
// destroy our own tolua interfaces
- LuaBind::getInstance().closeToluaInterfaces(this->luaState_);
+ LuaState::closeToluaInterfaces(this->luaState_);
}
/**
Modified: code/branches/resource2/src/core/GraphicsManager.cc
===================================================================
--- code/branches/resource2/src/core/GraphicsManager.cc 2009-08-17 13:42:39 UTC (rev 5653)
+++ code/branches/resource2/src/core/GraphicsManager.cc 2009-08-17 14:37:10 UTC (rev 5654)
@@ -44,6 +44,7 @@
#include <OgreException.h>
#include <OgreRenderWindow.h>
#include <OgreRenderSystem.h>
+#include <OgreResourceGroupManager.h>
#include <OgreViewport.h>
#include <OgreWindowEventUtilities.h>
@@ -58,7 +59,9 @@
#include "Core.h"
#include "Game.h"
#include "GameMode.h"
+#include "Loader.h"
#include "WindowEventListener.h"
+#include "XMLFile.h"
namespace orxonox
{
@@ -95,10 +98,24 @@
// load all the required plugins for Ogre
this->loadOgrePlugins();
+ // At first, add the root paths of the data directories as resource locations
+ Ogre::ResourceGroupManager::getSingleton().addResourceLocation(Core::getDataPathString(), "FileSystem", "dataRoot", false);
+ // Load resources
+ resources_.reset(new XMLFile("resources.oxr", "dataRoot"));
+ Loader::open(resources_.get());
+
+ // Only for development runs
+ if (Core::isDevelopmentRun())
+ {
+ Ogre::ResourceGroupManager::getSingleton().addResourceLocation(Core::getExternalDataPathString(), "FileSystem", "externalDataRoot", false);
+ extResources_.reset(new XMLFile("resources.oxr", "externalDataRoot"));
+ Loader::open(extResources_.get());
+ }
+
if (bLoadRenderer)
{
// Reads the ogre config and creates the render window
- this->loadRenderer();
+ this->upgradeToGraphics();
}
}
@@ -108,6 +125,7 @@
*/
GraphicsManager::~GraphicsManager()
{
+ // TODO: Destroy the console command
}
void GraphicsManager::setConfigValues()
@@ -136,10 +154,29 @@
*/
void GraphicsManager::upgradeToGraphics()
{
- if (renderWindow_ == NULL)
+ if (renderWindow_ != NULL)
+ return;
+
+ this->loadRenderer();
+
+ // RESOURCE MANAGEMENT
+
+ // Load graphical resources
+ resourcesGraphics_.reset(new XMLFile("resources_graphics.oxr", "dataRoot"));
+ Loader::open(resourcesGraphics_.get());
+
+ // Consider external data folder for dev runs
+ if (Core::isDevelopmentRun())
{
- this->loadRenderer();
+ extResourcesGraphics_.reset(new XMLFile("resources_graphics.oxr", "externalDataRoot"));
+ Loader::open(extResourcesGraphics_.get());
}
+
+ // Initialise all resources
+ // Note: You can only do this once! Ogre will check whether a resource group has
+ // already been initialised. If you need to load resources later, you will have to
+ // choose another resource group.
+ Ogre::ResourceGroupManager::getSingleton().initialiseAllResourceGroups();
}
/**
Modified: code/branches/resource2/src/core/GraphicsManager.h
===================================================================
--- code/branches/resource2/src/core/GraphicsManager.h 2009-08-17 13:42:39 UTC (rev 5653)
+++ code/branches/resource2/src/core/GraphicsManager.h 2009-08-17 14:37:10 UTC (rev 5654)
@@ -42,6 +42,7 @@
#include <string>
#include <OgreLog.h>
#include <boost/scoped_ptr.hpp>
+#include <boost/shared_ptr.hpp>
#include "util/Singleton.h"
#include "OrxonoxClass.h"
@@ -86,13 +87,18 @@
// console commands
void printScreen();
- private:
scoped_ptr<OgreWindowEventListener> ogreWindowEventListener_; //!< Pimpl to hide OgreWindowUtilities.h
scoped_ptr<Ogre::LogManager> ogreLogger_;
scoped_ptr<Ogre::Root> ogreRoot_; //!< Ogre's root
Ogre::RenderWindow* renderWindow_; //!< the one and only render window
Ogre::Viewport* viewport_; //!< default full size viewport
+ // XML files for the resources
+ shared_ptr<XMLFile> resources_; //!< XML with resource locations
+ shared_ptr<XMLFile> extResources_; //!< XML with resource locations in the external path (only for dev runs)
+ shared_ptr<XMLFile> resourcesGraphics_; //!< XML with resource locations (with renderer)
+ shared_ptr<XMLFile> extResourcesGraphics_; //!< XML with resource locations in the external path (only for dev runs) (with renderer)
+
// config values
std::string ogreConfigFile_; //!< ogre config file name
std::string ogrePluginsDirectory_; //!< Directory where the Ogre plugins are located
Modified: code/branches/resource2/src/core/Loader.cc
===================================================================
--- code/branches/resource2/src/core/Loader.cc 2009-08-17 13:42:39 UTC (rev 5653)
+++ code/branches/resource2/src/core/Loader.cc 2009-08-17 14:37:10 UTC (rev 5654)
@@ -28,15 +28,19 @@
#include "Loader.h"
+#include <sstream>
#include <tinyxml/ticpp.h>
+#include <boost/scoped_ptr.hpp>
#include "util/Debug.h"
#include "util/Exception.h"
+#include "util/StringUtils.h"
#include "BaseObject.h"
#include "Iterator.h"
#include "ObjectList.h"
-#include "LuaBind.h"
+#include "LuaState.h"
#include "Namespace.h"
+#include "Resource.h"
#include "XMLFile.h"
namespace orxonox
@@ -117,23 +121,19 @@
Loader::currentMask_s = file->getMask() * mask;
- // let Lua work this out:
- LuaBind& lua = LuaBind::getInstance();
- lua.clearLuaOutput();
- lua.loadFile(file->getFilename(), true);
- lua.run();
+ // Use the LuaState to replace the XML tags (calls our function)
+ scoped_ptr<LuaState> luaState(new LuaState());
+ luaState->setIncludeParser(&Loader::replaceLuaTags);
+ luaState->includeFile(file->getFilename(), file->getResourceGroup(), false);
+ //luaState->doString(luaInput);
try
{
COUT(0) << "Start loading " << file->getFilename() << "..." << std::endl;
COUT(3) << "Mask: " << Loader::currentMask_s << std::endl;
- //ticpp::Document xmlfile(file->getFilename());
- //xmlfile.LoadFile();
- //ticpp::Element myelement(*Script::getFileString());
- ticpp::Document xmlfile;
- //xmlfile.ToDocument();
- xmlfile.Parse(lua.getLuaOutput(), true);
+ ticpp::Document xmlfile(file->getFilename());
+ xmlfile.Parse(luaState->getOutput().str(), true);
ticpp::Element rootElement;
rootElement.SetAttribute("name", "root");
@@ -207,4 +207,155 @@
Loader::unload(file, mask);
return Loader::load(file, mask);
}
+
+ std::string Loader::replaceLuaTags(const std::string& text)
+ {
+ // chreate map with all Lua tags
+ std::map<size_t, bool> luaTags;
+ {
+ size_t pos = 0;
+ while ((pos = text.find("<?lua", pos)) != std::string::npos)
+ luaTags[pos++] = true;
+ }
+ {
+ size_t pos = 0;
+ while ((pos = text.find("?>", pos)) != std::string::npos)
+ luaTags[pos++] = false;
+ }
+
+ // erase all tags from the map that are between two quotes
+ {
+ std::map<size_t, bool>::iterator it = luaTags.begin();
+ std::map<size_t, bool>::iterator it2 = it;
+ bool bBetweenQuotes = false;
+ size_t pos = 0;
+ while ((pos = getNextQuote(text, pos)) != std::string::npos)
+ {
+ while ((it != luaTags.end()) && (it->first < pos))
+ {
+ if (bBetweenQuotes)
+ {
+ it2++;
+ if(it->second && !(it2->second) && it2->first < pos)
+ it = ++it2;
+ else
+ luaTags.erase(it++);
+ }
+ else
+ ++it;
+ }
+ bBetweenQuotes = !bBetweenQuotes;
+ pos++;
+ }
+ }
+
+ // check whether on every opening <?lua tag a closing ?> tag follows
+ {
+ bool expectedValue = true;
+ for (std::map<size_t, bool>::iterator it = luaTags.begin(); it != luaTags.end(); ++it)
+ {
+ if (it->second == expectedValue)
+ expectedValue = !expectedValue;
+ else
+ {
+ expectedValue = false;
+ break;
+ }
+ }
+ if (!expectedValue)
+ {
+ COUT(2) << "Warning: Error in level file" << std::endl;
+ // todo: errorhandling
+ return "";
+ }
+ }
+
+ // Use a stringstream object to speed up the parsing
+ std::ostringstream output;
+
+ // cut the original string into pieces and put them together with print() instead of lua tags
+ {
+ std::map<size_t, bool>::iterator it = luaTags.begin();
+ bool bInPrintFunction = true;
+ size_t start = 0;
+ size_t end = 0;
+
+ do
+ {
+ if (it != luaTags.end())
+ end = (*(it++)).first;
+ else
+ end = std::string::npos;
+
+ unsigned int equalSignCounter = 0;
+
+ if (bInPrintFunction)
+ {
+ // count ['='[ and ]'='] and replace tags with print([[ and ]])
+ std::string temp = text.substr(start, end - start);
+ {
+ size_t pos = 0;
+ while ((pos = temp.find('[', pos)) != std::string::npos)
+ {
+ unsigned int tempCounter = 1;
+ size_t tempPos = pos++;
+ while(temp[++tempPos] == '=')
+ {
+ tempCounter++;
+ }
+ if(temp[tempPos] != '[')
+ {
+ tempCounter = 0;
+ }
+ else if(tempCounter == 0)
+ {
+ tempCounter = 1;
+ }
+ if (tempCounter > equalSignCounter)
+ equalSignCounter = tempCounter;
+ }
+ }
+ {
+ size_t pos = 0;
+ while ((pos = temp.find(']', pos)) != std::string::npos)
+ {
+ unsigned int tempCounter = 1;
+ size_t tempPos = pos++;
+ while(temp[++tempPos] == '=')
+ {
+ tempCounter++;
+ }
+ if(temp[tempPos] != ']')
+ {
+ tempCounter = 0;
+ }
+ else if(tempCounter == 0)
+ {
+ tempCounter = 1;
+ }
+ if (tempCounter > equalSignCounter)
+ equalSignCounter = tempCounter;
+ }
+ }
+ std::string equalSigns = "";
+ for(unsigned int i = 0; i < equalSignCounter; i++)
+ {
+ equalSigns += "=";
+ }
+ output << "print([" + equalSigns + "[" + temp + "]" + equalSigns +"])";
+ start = end + 5;
+ }
+ else
+ {
+ output << text.substr(start, end - start);
+ start = end + 2;
+ }
+
+ bInPrintFunction = !bInPrintFunction;
+ }
+ while (end != std::string::npos);
+ }
+
+ return output.str();
+ }
}
Modified: code/branches/resource2/src/core/Loader.h
===================================================================
--- code/branches/resource2/src/core/Loader.h 2009-08-17 13:42:39 UTC (rev 5653)
+++ code/branches/resource2/src/core/Loader.h 2009-08-17 14:37:10 UTC (rev 5654)
@@ -54,6 +54,8 @@
static void unload(const XMLFile* file, const ClassTreeMask& mask = ClassTreeMask());
static bool reload(const XMLFile* file, const ClassTreeMask& mask = ClassTreeMask());
+ static std::string replaceLuaTags(const std::string& text);
+
static ClassTreeMask currentMask_s;
private:
Deleted: code/branches/resource2/src/core/LuaBind.cc
===================================================================
--- code/branches/resource2/src/core/LuaBind.cc 2009-08-17 13:42:39 UTC (rev 5653)
+++ code/branches/resource2/src/core/LuaBind.cc 2009-08-17 14:37:10 UTC (rev 5654)
@@ -1,343 +0,0 @@
-/*
- * ORXONOX - the hottest 3D action shooter ever to exist
- * > www.orxonox.net <
- *
- *
- * License notice:
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * Author:
- * Benjamin Knecht
- * Co-authors:
- * ...
- *
- */
-
-#include "LuaBind.h"
-
-#include <fstream>
-#include <map>
-extern "C" {
-#include <lualib.h>
-}
-#include <tolua/tolua++.h>
-#include <boost/filesystem.hpp>
-
-#include "util/Debug.h"
-#include "util/StringUtils.h"
-#include "Core.h"
-
-namespace orxonox
-{
- LuaBind* LuaBind::singletonPtr_s = NULL;
-
- LuaBind::LuaBind()
- {
- this->includePath_ = Core::getDataPathString();
-
- luaState_ = lua_open();
- luaSource_ = "";
-#if LUA_VERSION_NUM == 501
- luaL_openlibs(luaState_);
-#else
- luaopen_base(luaState_);
- luaopen_string(luaState_);
- luaopen_table(luaState_);
- luaopen_math(luaState_);
- luaopen_io(luaState_);
- luaopen_debug(luaState_);
-#endif
-
- // Open all available tolua interfaces
- this->openToluaInterfaces(luaState_);
-
- output_ = "";
- isRunning_ = false;
- }
-
- LuaBind::~LuaBind()
- {
- this->closeToluaInterfaces(luaState_);
- };
-
- void LuaBind::luaPrint(const std::string& str)
- {
- output_ += str;
-// COUT(4) << "Lua_output!:" << std::endl << str << std::endl << "***" << std::endl;
- COUT(5) << str;
- }
-
- /**
- @brief Loads the specified file line by line
- @param filename The filename of the file
- @param luaTags if true, the loaded file gets stripped off luaTags
- */
- void LuaBind::loadFile(const std::string& filename, bool luaTags)
- {
- boost::filesystem::path filepath(filename);
-
- output_ = "";
- std::ifstream file;
- file.open(filepath.string().c_str(), std::fstream::in);
-
- if (!file.is_open())
- {
- // some error msg
- }
-
- std::string levelString = "";
-
- while (file.good() && !file.eof())
- {
- std::string line;
- std::getline(file, line);
- levelString += line;
- levelString += "\n";
- }
-
- file.close();
- //std::string output;
-
- if (luaTags)
- luaSource_ = replaceLuaTags(levelString);
- else
- luaSource_ = levelString;
- COUT(5) << "ParsedSourceCode: " << luaSource_ << std::endl;
- }
-
- void LuaBind::loadString(const std::string& code)
- {
- luaSource_ = code;
- output_ = "";
- }
-
-#if LUA_VERSION_NUM != 501
- const char * LuaBind::lua_Chunkreader(lua_State *L, void *data, size_t *size)
- {
- LoadS* ls = static_cast<LoadS*>(data);
- if (ls->size == 0) return NULL;
- *size = ls->size;
- ls->size = 0;
- return ls->s;
- }
-#endif
- void LuaBind::run()
- {
- if (!isRunning_)
- {
- isRunning_ = true;
- int error = 0;
- std::string init =
- "local scr = orxonox.LuaBind:getInstance()\n \
- local debug = print\n \
- print = function(s)\n \
- scr:luaPrint(s)\n \
- end\n \
- include = function(f)\n \
- file = assert(io.open(\"" + this->includePath_ + "\"..\"/\"..f))\n \
- content = file:read(\"*a\")\n \
- file:close()\n \
- source = scr:replaceLuaTags(content)\n \
- assert(loadstring(source))()\n \
- end\n";
- init += luaSource_;
- #if LUA_VERSION_NUM == 501
- error = luaL_loadstring(luaState_, init.c_str());
- #else
- LoadS ls;
- ls.s = init.c_str();
- ls.size = init.size();
- error = lua_load(luaState_, &orxonox::LuaBind::lua_Chunkreader, &ls, init.c_str());
- #endif
- if (error == 0)
- {
- error = lua_pcall(luaState_, 0, 0, 0);
- }
- if (error != 0)
- {
- COUT(2) << "Error in Lua-script: " << lua_tostring(luaState_, -1) << std::endl;
- }
- isRunning_ = false;
- }
- else
- {
- COUT(2) << "Warning: Lua's run is called while running!" << std::endl;
- }
- }
-
- std::string LuaBind::replaceLuaTags(const std::string& text)
- {
- // chreate map with all Lua tags
- std::map<size_t, bool> luaTags;
- {
- size_t pos = 0;
- while ((pos = text.find("<?lua", pos)) != std::string::npos)
- luaTags[pos++] = true;
- }
- {
- size_t pos = 0;
- while ((pos = text.find("?>", pos)) != std::string::npos)
- luaTags[pos++] = false;
- }
-
- // erase all tags from the map that are between two quotes
- {
- std::map<size_t, bool>::iterator it = luaTags.begin();
- std::map<size_t, bool>::iterator it2 = it;
- bool bBetweenQuotes = false;
- size_t pos = 0;
- while ((pos = getNextQuote(text, pos)) != std::string::npos)
- {
- while ((it != luaTags.end()) && (it->first < pos))
- {
- if (bBetweenQuotes) {
- it2++;
- if(it->second && !(it2->second) && it2->first < pos)
- it = ++it2;
- else
- luaTags.erase(it++);
- }
- else
- ++it;
- }
- bBetweenQuotes = !bBetweenQuotes;
- pos++;
- }
- }
-
- // check whether on every opening <?lua tag a closing ?> tag follows
- {
- bool expectedValue = true;
- for (std::map<size_t, bool>::iterator it = luaTags.begin(); it != luaTags.end(); ++it)
- {
- if (it->second == expectedValue)
- expectedValue = !expectedValue;
- else
- {
- expectedValue = false;
- break;
- }
- }
- if (!expectedValue) {
- COUT(2) << "Warning: Error in level file" << std::endl;
- // todo: errorhandling
- return "";
- }
- }
-
- // cut the original string into pieces and put them together with print() instead of lua tags
- std::string output;
- {
- std::map<size_t, bool>::iterator it = luaTags.begin();
- bool bInPrintFunction = true;
- size_t start = 0;
- size_t end = 0;
-
- do
- {
- if (it != luaTags.end())
- end = (*(it++)).first;
- else
- end = std::string::npos;
-
- unsigned int equalSignCounter = 0;
-
- if (bInPrintFunction)
- {
- // count ['='[ and ]'='] and replace tags with print([[ and ]])
- std::string temp = text.substr(start, end - start);
- {
- size_t pos = 0;
- while ((pos = temp.find('[', pos)) != std::string::npos)
- {
- unsigned int tempCounter = 1;
- size_t tempPos = pos++;
- while(temp[++tempPos] == '=') {
- tempCounter++;
- }
- if(temp[tempPos] != '[') {
- tempCounter = 0;
- }
- else if(tempCounter == 0) {
- tempCounter = 1;
- }
- if (tempCounter > equalSignCounter)
- equalSignCounter = tempCounter;
- }
- }
- {
- size_t pos = 0;
- while ((pos = temp.find(']', pos)) != std::string::npos)
- {
- unsigned int tempCounter = 1;
- size_t tempPos = pos++;
- while(temp[++tempPos] == '=') {
- tempCounter++;
- }
- if(temp[tempPos] != ']') {
- tempCounter = 0;
- }
- else if(tempCounter == 0) {
- tempCounter = 1;
- }
- if (tempCounter > equalSignCounter)
- equalSignCounter = tempCounter;
- }
- }
- std::string equalSigns = "";
- for(unsigned int i = 0; i < equalSignCounter; i++) {
- equalSigns += "=";
- }
- output += "print([" + equalSigns + "[" + temp + "]" + equalSigns +"])";
- start = end + 5;
- }
- else
- {
- output += text.substr(start, end - start);
- start = end + 2;
- }
-
- bInPrintFunction = !bInPrintFunction;
- }
- while (end != std::string::npos);
- }
-
- return output;
- }
-
- void LuaBind::addToluaInterface(int (*function)(lua_State*), const std::string& name)
- {
- toluaInterfaces_.push_back(std::make_pair(name, function));
- // Apply changes to our own lua state as well
- (*function)(luaState_);
- }
-
- void LuaBind::openToluaInterfaces(lua_State* state)
- {
- for (unsigned int i = 0; i < toluaInterfaces_.size(); ++i)
- (*toluaInterfaces_[i].second)(state);
- }
-
- void LuaBind::closeToluaInterfaces(lua_State* state)
- {
- for (unsigned int i = 0; i < toluaInterfaces_.size(); ++i)
- {
- lua_pushnil(state);
- lua_setglobal(state, toluaInterfaces_[i].first.c_str());
- }
- }
-
-}
Deleted: code/branches/resource2/src/core/LuaBind.h
===================================================================
--- code/branches/resource2/src/core/LuaBind.h 2009-08-17 13:42:39 UTC (rev 5653)
+++ code/branches/resource2/src/core/LuaBind.h 2009-08-17 14:37:10 UTC (rev 5654)
@@ -1,105 +0,0 @@
-/*
- * ORXONOX - the hottest 3D action shooter ever to exist
- * > www.orxonox.net <
- *
- *
- * License notice:
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * Author:
- * Benjamin Knecht
- * Co-authors:
- * ...
- *
- */
-
-/**
- @file
- @brief Representation of an interface to lua
- @author Benjamin Knecht <beni_at_orxonox.net>
- */
-
-#ifndef _LuaBind_H__
-#define _LuaBind_H__
-
-#include "CorePrereqs.h"
-
-#include <cassert>
-#include <string>
-#include <vector>
-extern "C" {
-#include <lua.h>
-}
-
-#include "util/Singleton.h"
-
-// tolua_begin
-namespace orxonox
-{
- class _CoreExport LuaBind : public Singleton<LuaBind>
- {
-// tolua_end
- friend class Singleton<LuaBind>;
-
- struct LoadS {
- const char *s;
- size_t size;
- };
-
- public:
- LuaBind();
- ~LuaBind();
-
- static LuaBind& getInstance() { return Singleton<LuaBind>::getInstance(); } // tolua_export
-
- void loadFile(const std::string& filename, bool luaTags);
- void loadString(const std::string& code);
- //void init(lua_State *state_);
- //void xmlToLua();
- void run();
- void luaPrint(const std::string& str); // tolua_export
-
-#if LUA_VERSION_NUM != 501
- static const char * lua_Chunkreader(lua_State *L, void *data, size_t *size);
-#endif
-
- inline lua_State* getLuaState() { return luaState_; };
- inline const std::string& getLuaOutput() { return output_; };
- //inline std::string* getFileString() { return &fileString_; };
- inline void clearLuaOutput() { output_ = ""; }
-
- std::string replaceLuaTags(const std::string& text); // tolua_export
-
- inline void setIncludePath(const std::string& includepath)
- { this->includePath_ = includepath; }
-
- void addToluaInterface(int (*function)(lua_State*), const std::string& name);
- void openToluaInterfaces(lua_State* state);
- void closeToluaInterfaces(lua_State* state);
-
- private:
- static LuaBind* singletonPtr_s;
-
- std::string luaSource_;
- std::string output_;
- lua_State* luaState_;
- bool isRunning_;
- std::string includePath_;
- std::vector<std::pair<std::string, int (*)(lua_State *L)> > toluaInterfaces_;
-
- }; // tolua_export
-} // tolua_export
-#endif /* _LuaBind_H__ */
Copied: code/branches/resource2/src/core/LuaState.cc (from rev 5645, code/branches/resource2/src/core/LuaBind.cc)
===================================================================
--- code/branches/resource2/src/core/LuaState.cc (rev 0)
+++ code/branches/resource2/src/core/LuaState.cc 2009-08-17 14:37:10 UTC (rev 5654)
@@ -0,0 +1,261 @@
+/*
+ * ORXONOX - the hottest 3D action shooter ever to exist
+ * > www.orxonox.net <
+ *
+ *
+ * License notice:
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * Author:
+ * Benjamin Knecht
+ * Reto Grieder
+ * Co-authors:
+ * ...
+ *
+ */
+
+#include "LuaState.h"
+
+#include <tolua/tolua++.h>
+extern "C" {
+#include <lua.h>
+#include <lualib.h>
+}
+
+#include "util/Debug.h"
+#include "Core.h"
+#include "Resource.h"
+
+namespace orxonox
+{
+ LuaState::ToluaInterfaceMap LuaState::toluaInterfaces_s;
+ std::vector<LuaState*> LuaState::instances_s;
+
+ LuaState::LuaState()
+ : bIsRunning_(false)
+ , includeParseFunction_(NULL)
+ {
+ // Create new lua state and configure it
+ luaState_ = lua_open();
+#if LUA_VERSION_NUM == 501
+ luaL_openlibs(luaState_);
+#else
+ luaopen_base(luaState_);
+ luaopen_string(luaState_);
+ luaopen_table(luaState_);
+ luaopen_math(luaState_);
+ luaopen_io(luaState_);
+ luaopen_debug(luaState_);
+#endif
+
+ // Open all available tolua interfaces
+ this->openToluaInterfaces(luaState_);
+
+ // Create dummy file info
+ sourceFileInfo_.reset(new ResourceInfo());
+ sourceFileInfo_->group = "General";
+ sourceFileInfo_->size = 0;
+
+ // Push this pointer
+ tolua_pushusertype(luaState_, static_cast<void*>(this), "orxonox::LuaState");
+ lua_setglobal(luaState_, "luaState");
+
+ // Parse init script
+ // Note: We have to use a hard coded path because the script is required for the resource loading
+ this->doString("dofile(\"" + Core::getDataPathString() + "lua/LuaStateInit.lua\")");
+ }
+
+ LuaState::~LuaState()
+ {
+ lua_close(luaState_);
+ }
+
+ shared_ptr<ResourceInfo> LuaState::getFileInfo(const std::string& filename, const std::string& resourceGroup, bool bSearchOtherPaths)
+ {
+ shared_ptr<ResourceInfo> sourceInfo;
+ if (resourceGroup != "NoResourceGroupProvided")
+ sourceInfo = Resource::getInfo(filename, resourceGroup);
+
+ // Continue search if not explicitely forbidden
+ if (bSearchOtherPaths && sourceInfo == NULL)
+ {
+ // Call might be relative to the file currently being processed
+ sourceInfo = Resource::getInfo(sourceFileInfo_->path + filename, sourceFileInfo_->group);
+ if (sourceInfo == NULL)
+ {
+ // Maybe find something in the same group but in the root path
+ sourceInfo = Resource::getInfo(filename, sourceFileInfo_->group);
+ }
+ }
+ return sourceInfo;
+ }
+
+ void LuaState::includeFile(const std::string& filename, const std::string& resourceGroup, bool bSearchOtherPaths)
+ {
+ shared_ptr<ResourceInfo> sourceInfo = this->getFileInfo(filename, resourceGroup, bSearchOtherPaths);
+ if (sourceInfo != NULL)
+ this->includeString(Resource::open(sourceInfo->filename, sourceInfo->group)->getAsString(), sourceInfo);
+ else
+ COUT(2) << "LuaState: Cannot include file '" << filename << "' in resource group '"
+ << (resourceGroup == "NoResourceGroupProvided" ? sourceFileInfo_->group : resourceGroup) << "': group not found." << std::endl;
+ }
+
+ void LuaState::includeString(const std::string& code, shared_ptr<ResourceInfo> sourceFileInfo)
+ {
+ // Parse string with provided include parser (otherwise don't preparse at all)
+ std::string luaInput;
+ if (includeParseFunction_ != NULL)
+ luaInput = (*includeParseFunction_)(code);
+ else
+ luaInput = code;
+
+ this->doString(luaInput, sourceFileInfo);
+ }
+
+ void LuaState::doFile(const std::string& filename, const std::string& resourceGroup, bool bSearchOtherPaths)
+ {
+ shared_ptr<ResourceInfo> sourceInfo = this->getFileInfo(filename, resourceGroup, bSearchOtherPaths);
+ if (sourceInfo != NULL)
+ this->doString(Resource::open(sourceInfo->filename, sourceInfo->group)->getAsString(), sourceInfo);
+ else
+ COUT(2) << "LuaState: Cannot do file '" << filename << "' in resource group '"
+ << (resourceGroup == "NoResourceGroupProvided" ? sourceFileInfo_->group : resourceGroup) << "': group not found." << std::endl;
+ }
+
+ void LuaState::doString(const std::string& code, shared_ptr<ResourceInfo> sourceFileInfo)
+ {
+ // Save the oold source file info
+ shared_ptr<ResourceInfo> oldSourceFileInfo = sourceFileInfo_;
+ // Only override if sourceFileInfo provides useful information
+ if (sourceFileInfo != NULL)
+ sourceFileInfo_ = sourceFileInfo;
+
+ //if (!bIsRunning_)
+ //{
+ // bIsRunning_ = true;
+
+ int error = 0;
+#if LUA_VERSION_NUM != 501
+ LoadS ls;
+ ls.s = code.c_str();
+ ls.size = code.size();
+ error = lua_load(luaState_, &orxonox::LuaState::lua_Chunkreader, &ls, code.c_str());
+#else
+ error = luaL_loadstring(luaState_, code.c_str());
+#endif
+
+ // execute the chunk
+ if (error == 0)
+ error = lua_pcall(luaState_, 0, 0, 0);
+ if (error != 0)
+ {
+ std::string origin;
+ if (sourceFileInfo != NULL)
+ origin = " originating from " + sourceFileInfo_->filename;
+ COUT(2) << "Error in Lua-script" << origin << ": " << lua_tostring(luaState_, -1) << std::endl;
+ }
+
+ // bIsRunning_ = false;
+ //}
+ //else
+ //{
+ // COUT(2) << "Warning: LuaState do function called while running!" << std::endl;
+ //}
+
+ // Load the old info again
+ sourceFileInfo_ = oldSourceFileInfo;
+ }
+
+ void LuaState::luaPrint(const std::string& str)
+ {
+ output_ << str;
+ }
+
+ void LuaState::luaLog(unsigned int level, const std::string& message)
+ {
+ OutputHandler::getOutStream().setOutputLevel(level) << message << std::endl;
+ }
+
+#if LUA_VERSION_NUM != 501
+ const char * LuaState::lua_Chunkreader(lua_State *L, void *data, size_t *size)
+ {
+ LoadS* ls = static_cast<LoadS*>(data);
+ if (ls->size == 0)
+ return NULL;
+ *size = ls->size;
+ ls->size = 0;
+ return ls->s;
+ }
+#endif
+
+ /*static*/ bool LuaState::addToluaInterface(int (*function)(lua_State*), const std::string& name)
+ {
+ for (ToluaInterfaceMap::const_iterator it = toluaInterfaces_s.begin(); it != toluaInterfaces_s.end(); ++it)
+ {
+ if (it->first == name || it->second == function)
+ {
+ COUT(2) << "Warning: Trying to add a Tolua interface with the same name or function." << std::endl;
+ return true;
+ }
+ }
+ toluaInterfaces_s[name] = function;
+
+ // Open interface in all LuaStates
+ for (std::vector<LuaState*>::const_iterator it = instances_s.begin(); it != instances_s.end(); ++it)
+ (*function)((*it)->luaState_);
+
+ // Return dummy bool
+ return true;
+ }
+
+ /*static*/ bool LuaState::removeToluaInterface(const std::string& name)
+ {
+ ToluaInterfaceMap::iterator it = toluaInterfaces_s.find(name);
+ if (it == toluaInterfaces_s.end())
+ {
+ COUT(2) << "Warning: Cannot remove Tolua interface '" << name << "': Not found" << std::endl;
+ return true;
+ }
+
+ // Close interface in all LuaStates
+ for (std::vector<LuaState*>::const_iterator itState = instances_s.begin(); itState != instances_s.end(); ++itState)
+ {
+ lua_pushnil((*itState)->luaState_);
+ lua_setglobal((*itState)->luaState_, it->first.c_str());
+ }
+
+ // Remove entry
+ toluaInterfaces_s.erase(it);
+
+ // Return dummy bool
+ return true;
+ }
+
+ /*static*/ void LuaState::openToluaInterfaces(lua_State* state)
+ {
+ for (ToluaInterfaceMap::const_iterator it = toluaInterfaces_s.begin(); it != toluaInterfaces_s.end(); ++it)
+ (*it->second)(state);
+ }
+
+ /*static*/ void LuaState::closeToluaInterfaces(lua_State* state)
+ {
+ for (ToluaInterfaceMap::const_iterator it = toluaInterfaces_s.begin(); it != toluaInterfaces_s.end(); ++it)
+ {
+ lua_pushnil(state);
+ lua_setglobal(state, it->first.c_str());
+ }
+ }
+}
Copied: code/branches/resource2/src/core/LuaState.h (from rev 5645, code/branches/resource2/src/core/LuaBind.h)
===================================================================
--- code/branches/resource2/src/core/LuaState.h (rev 0)
+++ code/branches/resource2/src/core/LuaState.h 2009-08-17 14:37:10 UTC (rev 5654)
@@ -0,0 +1,102 @@
+/*
+ * ORXONOX - the hottest 3D action shooter ever to exist
+ * > www.orxonox.net <
+ *
+ *
+ * License notice:
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * Author:
+ * Benjamin Knecht
+ * Reto Grieder
+ * Co-authors:
+ * ...
+ *
+ */
+
+#ifndef _LuaState_H__
+#define _LuaState_H__
+
+#include "CorePrereqs.h"
+
+#include <map>
+#include <sstream>
+#include <string>
+#include <vector>
+#include <boost/shared_ptr.hpp>
+
+#include "util/ScopeGuard.h"
+
+// tolua_begin
+namespace orxonox
+{
+ /**
+ @brief
+ Representation of an interface to lua
+ */
+ class _CoreExport LuaState
+ {
+// tolua_end
+ public:
+ LuaState();
+ ~LuaState();
+
+ void doFile(const std::string& filename, const std::string& resourceGroup = "General", bool bSearchOtherPaths = true); // tolua_export
+ void doString(const std::string& code, shared_ptr<ResourceInfo> sourceFileInfo = shared_ptr<ResourceInfo>());
+
+ void includeFile(const std::string& filename, const std::string& resourceGroup = "Genreal", bool bSearchOtherPaths = true); // tolua_export
+ void includeString(const std::string& code, shared_ptr<ResourceInfo> sourceFileInfo = shared_ptr<ResourceInfo>());
+
+ void luaPrint(const std::string& str); // tolua_export
+ void luaLog(unsigned int level, const std::string& message); // tolua_export
+
+ const std::stringstream& getOutput() const { return output_; }
+ void clearOutput() { output_.clear(); } // tolua_export
+
+ void setIncludeParser(std::string (*function)(const std::string&)) { includeParseFunction_ = function; }
+ lua_State* getInternalLuaState() { return luaState_; }
+
+ static bool addToluaInterface(int (*function)(lua_State*), const std::string& name);
+ static bool removeToluaInterface(const std::string& name);
+ static void openToluaInterfaces(lua_State* state);
+ static void closeToluaInterfaces(lua_State* state);
+
+ private:
+ shared_ptr<ResourceInfo> getFileInfo(const std::string& filename, const std::string& resourceGroup, bool bSearchOtherPaths);
+
+#if LUA_VERSION_NUM != 501
+ struct LoadS
+ {
+ const char* s;
+ size_t size;
+ };
+
+ static const char * lua_Chunkreader(lua_State *L, void *data, size_t *size);
+#endif
+
+ std::stringstream output_;
+ lua_State* luaState_;
+ bool bIsRunning_;
+ shared_ptr<ResourceInfo> sourceFileInfo_;
+ std::string (*includeParseFunction_)(const std::string&);
+
+ typedef std::map<std::string, int (*)(lua_State *L)> ToluaInterfaceMap;
+ static ToluaInterfaceMap toluaInterfaces_s;
+ static std::vector<LuaState*> instances_s;
+ }; // tolua_export
+} // tolua_export
+
+#endif /* _LuaState_H__ */
Modified: code/branches/resource2/src/orxonox/gamestates/GSGraphics.cc
===================================================================
--- code/branches/resource2/src/orxonox/gamestates/GSGraphics.cc 2009-08-17 13:42:39 UTC (rev 5653)
+++ code/branches/resource2/src/orxonox/gamestates/GSGraphics.cc 2009-08-17 14:37:10 UTC (rev 5654)
@@ -95,7 +95,7 @@
{
// load debug overlay
COUT(3) << "Loading Debug Overlay..." << std::endl;
- this->debugOverlay_ = new XMLFile(Core::getDataPathString() + "overlay/debug.oxo");
+ this->debugOverlay_ = new XMLFile("debug.oxo");
Loader::open(debugOverlay_);
masterKeyBinder_->loadBindings("masterKeybindings.ini");
Modified: code/branches/resource2/src/orxonox/gamestates/GSLevel.cc
===================================================================
--- code/branches/resource2/src/orxonox/gamestates/GSLevel.cc 2009-08-17 13:42:39 UTC (rev 5653)
+++ code/branches/resource2/src/orxonox/gamestates/GSLevel.cc 2009-08-17 14:37:10 UTC (rev 5654)
@@ -245,7 +245,7 @@
{
// call the loader
COUT(0) << "Loading level..." << std::endl;
- startFile_s = new XMLFile(Core::getDataPathString() + "levels" + '/' + LevelManager::getInstance().getDefaultLevel());
+ startFile_s = new XMLFile(LevelManager::getInstance().getDefaultLevel());
Loader::open(startFile_s);
}
Modified: code/branches/resource2/src/orxonox/gamestates/GSRoot.cc
===================================================================
--- code/branches/resource2/src/orxonox/gamestates/GSRoot.cc 2009-08-17 13:42:39 UTC (rev 5653)
+++ code/branches/resource2/src/orxonox/gamestates/GSRoot.cc 2009-08-17 14:37:10 UTC (rev 5654)
@@ -32,9 +32,8 @@
#include "core/ConsoleCommand.h"
#include "core/Game.h"
#include "core/GameMode.h"
-#include "core/LuaBind.h"
+#include "core/LuaState.h"
#include "network/NetworkFunction.h"
-#include "ToluaBindCore.h"
#include "ToluaBindOrxonox.h"
#include "tools/Timer.h"
#include "interfaces/TimeFactorListener.h"
@@ -55,8 +54,7 @@
this->ccPause_ = 0;
// Tell LuaBind about all tolua interfaces
- LuaBind::getInstance().addToluaInterface(&tolua_Core_open, "Core");
- LuaBind::getInstance().addToluaInterface(&tolua_Orxonox_open, "Orxonox");
+ LuaState::addToluaInterface(&tolua_Orxonox_open, "Orxonox");
}
GSRoot::~GSRoot()
@@ -85,7 +83,7 @@
CommandExecutor::addConsoleCommandShortcut(this->ccPause_).accessLevel(AccessLevel::Offline);
}
- // create the global LevelManager
+ // create the LevelManager
this->levelManager_ = new LevelManager();
}
Modified: code/branches/resource2/src/orxonox/objects/Level.cc
===================================================================
--- code/branches/resource2/src/orxonox/objects/Level.cc 2009-08-17 13:42:39 UTC (rev 5653)
+++ code/branches/resource2/src/orxonox/objects/Level.cc 2009-08-17 14:37:10 UTC (rev 5654)
@@ -52,9 +52,6 @@
this->registerVariables();
this->xmlfilename_ = this->getFilename();
-
- if (this->xmlfilename_.length() >= Core::getDataPathString().length())
- this->xmlfilename_ = this->xmlfilename_.substr(Core::getDataPathString().length());
}
Level::~Level()
Modified: code/branches/resource2/src/orxonox/objects/Script.cc
===================================================================
--- code/branches/resource2/src/orxonox/objects/Script.cc 2009-08-17 13:42:39 UTC (rev 5653)
+++ code/branches/resource2/src/orxonox/objects/Script.cc 2009-08-17 14:37:10 UTC (rev 5654)
@@ -28,41 +28,37 @@
#include "Script.h"
-#include <tinyxml/ticpp.h>
#include "core/CoreIncludes.h"
-#include "core/LuaBind.h"
+#include "core/LuaState.h"
+#include "core/XMLPort.h"
namespace orxonox
{
- CreateFactory(Script);
+ CreateFactory(Script);
- Script::Script(BaseObject* creator) : BaseObject(creator)
- {
- RegisterObject(Script);
+ Script::Script(BaseObject* creator) : BaseObject(creator)
+ {
+ RegisterObject(Script);
- code_ = "";
- }
+ // Get a new LuaState
+ luaState_ = new LuaState();
+ }
- Script::~Script()
- {
- }
+ Script::~Script()
+ {
+ if (this->isInitialized())
+ delete luaState_;
+ }
- /**
- @brief XML loading and saving.
- @param xmlelement The XML-element
- @param loading Loading (true) or saving (false)
- */
- void Script::XMLPort(Element& xmlelement, XMLPort::Mode mode)
- {
- BaseObject::XMLPort(xmlelement, mode);
+ void Script::XMLPort(Element& xmlelement, XMLPort::Mode mode)
+ {
+ BaseObject::XMLPort(xmlelement, mode);
- code_ = xmlelement.GetText(false);
- }
+ XMLPortParam(Script, "code", setCode, getCode, xmlelement, mode);
+ }
- void Script::execute()
- {
- LuaBind& lua = LuaBind::getInstance();
- lua.loadString(this->code_);
- lua.run();
- }
+ void Script::execute()
+ {
+ luaState_->doString(code_);
+ }
}
Modified: code/branches/resource2/src/orxonox/objects/Script.h
===================================================================
--- code/branches/resource2/src/orxonox/objects/Script.h 2009-08-17 13:42:39 UTC (rev 5653)
+++ code/branches/resource2/src/orxonox/objects/Script.h 2009-08-17 14:37:10 UTC (rev 5654)
@@ -36,17 +36,21 @@
namespace orxonox
{
- class _OrxonoxExport Script : public BaseObject
- {
+ class _OrxonoxExport Script : public BaseObject
+ {
public:
- Script(BaseObject* creator);
- ~Script();
- void XMLPort(Element& xmlelement, XMLPort::Mode mode);
- void execute();
+ Script(BaseObject* creator);
+ ~Script();
+ void XMLPort(Element& xmlelement, XMLPort::Mode mode);
+ void execute();
+ void setCode(const std::string& code) { code_ = code; }
+ const std::string& getCode() const { return code_; }
+
private:
- std::string code_;
- };
+ std::string code_;
+ LuaState* luaState_;
+ };
}
#endif /* _Script_H__ */
Modified: code/branches/resource2/src/orxonox/sound/SoundBase.cc
===================================================================
--- code/branches/resource2/src/orxonox/sound/SoundBase.cc 2009-08-17 13:42:39 UTC (rev 5653)
+++ code/branches/resource2/src/orxonox/sound/SoundBase.cc 2009-08-17 14:37:10 UTC (rev 5654)
@@ -35,6 +35,7 @@
#include "util/Math.h"
#include "core/Core.h"
+#include "core/Resource.h"
#include "orxonox/objects/worldentities/WorldEntity.h"
#include "SoundManager.h"
@@ -133,9 +134,7 @@
return true;
}
- bool SoundBase::loadFile(std::string filename) {
- filename = Core::getDataPathString() + "/audio/" + filename;
-
+ bool SoundBase::loadFile(const std::string& filename) {
if(!SoundManager::getInstance().isSoundAvailable())
{
COUT(3) << "Sound: not available, skipping " << filename << std::endl;
@@ -143,7 +142,20 @@
}
COUT(3) << "Sound: OpenAL ALUT: loading file " << filename << std::endl;
- this->buffer_ = alutCreateBufferFromFile(filename.c_str());
+ // Get DataStream from the resources
+ shared_ptr<ResourceInfo> fileInfo = Resource::getInfo(filename);
+ if (fileInfo == NULL) {
+ COUT(2) << "Warning: Sound file '" << filename << "' not found" << std::endl;
+ return false;
+ }
+ DataStreamPtr stream = Resource::open(filename);
+ // Read everything into a temporary buffer
+ char* buffer = new char[fileInfo->size];
+ stream->read(buffer, fileInfo->size);
+
+ this->buffer_ = alutCreateBufferFromFileImage(buffer, fileInfo->size);
+ delete[] buffer;
+
if(this->buffer_ == AL_NONE) {
COUT(2) << "Sound: OpenAL ALUT: " << alutGetErrorString(alutGetError()) << std::endl;
if(filename.find("ogg", 0) != std::string::npos)
Modified: code/branches/resource2/src/orxonox/sound/SoundBase.h
===================================================================
--- code/branches/resource2/src/orxonox/sound/SoundBase.h 2009-08-17 13:42:39 UTC (rev 5653)
+++ code/branches/resource2/src/orxonox/sound/SoundBase.h 2009-08-17 14:37:10 UTC (rev 5654)
@@ -54,7 +54,7 @@
bool isPaused();
bool isStopped();
- bool loadFile(std::string filename);
+ bool loadFile(const std::string& filename);
private:
ALuint loadOggFile(const std::string& filename);
Deleted: data/branches/media_stripped/resources.cfg
===================================================================
--- data/branches/media_stripped/resources.cfg 2009-08-17 13:42:39 UTC (rev 5653)
+++ data/branches/media_stripped/resources.cfg 2009-08-17 14:37:10 UTC (rev 5654)
@@ -1,34 +0,0 @@
-# Resource locations to be added to the 'boostrap' path
-# This also contains the minimum you need to use the Ogre example framework
-[Bootstrap]
-Zip=packs/OgreCore.zip
-
-# Resource locations to be added to the default path
-[General]
-FileSystem=.
-FileSystem=fonts
-FileSystem=materials/programs
-FileSystem=materials/scripts
-FileSystem=materials/textures
-FileSystem=models
-FileSystem=overlay
-FileSystem=particle
-#FileSystem=../Media/levels
-#FileSystem=../Media/audio
-Zip=packs/cubemap.zip
-#Zip=../Media/packs/cubemapsJS.zip
-#Zip=../Media/packs/dragon.zip
-#Zip=../Media/packs/fresneldemo.zip
-#Zip=../Media/packs/ogretestmap.zip
-Zip=packs/skybox.zip
-FileSystem=gui/fonts
-
-# CEGUI files
-[GUI]
-FileSystem=gui/configs
-FileSystem=gui/fonts
-FileSystem=gui/imagesets
-FileSystem=gui/layouts
-FileSystem=gui/looknfeel
-FileSystem=gui/schemes
-FileSystem=gui/scripts
Modified: data/branches/media_stripped/resources.oxr
===================================================================
--- data/branches/media_stripped/resources.oxr 2009-08-17 13:42:39 UTC (rev 5653)
+++ data/branches/media_stripped/resources.oxr 2009-08-17 14:37:10 UTC (rev 5654)
@@ -1,19 +1,5 @@
-<ResourceGroup name = "General" >
- <ResourceLocation path = overlay />
- <ResourceLocation path = particle />
- <ResourceLocation path = defaultConfig />
- <ResourceLocation path = levels />
- <ResourceLocation path = tcl />
- <ResourceLocation
- path = test.zip
- archive = Zip
- recursive = true
- />
-</ResourceGroup>
+<ResourceCollection resourceGroup = "General" >
+</ResourceCollection>
-<ResourceGroup name = "GUI" >
- <ResourceLocation path = gui/configs />
- <ResourceLocation path = gui/layouts />
- <ResourceLocation path = gui/schemas />
- <ResourceLocation path = gui/scripts />
-</ResourceGroup>
+<ResourceCollection resourceGroup = "GUI" >
+</ResourceCollection>
Copied: data/branches/media_stripped/resources_graphics.oxr (from rev 5645, data/branches/media_stripped/resources.oxr)
===================================================================
--- data/branches/media_stripped/resources_graphics.oxr (rev 0)
+++ data/branches/media_stripped/resources_graphics.oxr 2009-08-17 14:37:10 UTC (rev 5654)
@@ -0,0 +1,17 @@
+<ResourceCollection resourceGroup = "General" >
+ <ResourceLocation path = "audio" />
+ <ResourceLocation path = "fonts" />
+ <ResourceLocation path = "materials/programs" />
+ <ResourceLocation path = "materials/scripts" />
+ <ResourceLocation path = "materials/textures" />
+ <ResourceLocation path = "models" />
+ <ResourceLocation path = "gui/fonts" />
+ <ResourceLocation path = "packs/cubemap.zip" archiveType = "Zip" />
+ <ResourceLocation path = "packs/skybox.zip" archiveType = "Zip" />
+</ResourceCollection>
+
+<ResourceCollection resourceGroup = "GUI" >
+ <ResourceLocation path = "gui/fonts" />
+ <ResourceLocation path = "gui/imagesets" />
+ <ResourceLocation path = "gui/looknfeel" />
+</ResourceCollection>
More information about the Orxonox-commit
mailing list