Skip to content

Commit

Permalink
Merge branch 'master' of git://github.com/anddrewscott/rapanui
Browse files Browse the repository at this point in the history
  • Loading branch information
eljeko committed Feb 13, 2012
2 parents ee78041 + a3dde91 commit d95247b
Show file tree
Hide file tree
Showing 10 changed files with 82 additions and 36 deletions.
1 change: 1 addition & 0 deletions .gitignore
@@ -0,0 +1 @@
lua/
17 changes: 12 additions & 5 deletions RNDirector.lua
Expand Up @@ -58,11 +58,18 @@ function RNDirector:setTime(value)
TIME = value
end

local coll = collectgarbage
local unloadScene = function ( moduleName )
if moduleName ~= "main" and type( package.loaded[moduleName] ) == "table" then
package.loaded[moduleName] = nil
coll()
end
end

--Functions to show/hide a scene with the given effect
function RNDirector:showScene(name, effect)

if name ~= nil then
unloadScene(name) -- clean this
NEXT_SCENE = require(name)
else
NEXT_SCENE = nil
Expand All @@ -71,13 +78,13 @@ function RNDirector:showScene(name, effect)
if TRANSITIONING == false then
TRANSITIONING = true
if effect == "slidetoleft" then
self:slideout(config.width, 0)
self:slideout(config.PW, 0)
elseif effect == "slidetoright" then
self:slideout(-config.width, 0)
self:slideout(-config.PW, 0)
elseif effect == "slidetotop" then
self:slideout(0, config.height)
self:slideout(0, config.PH)
elseif effect == "slidetobottom" then
self:slideout(0, -config.height)
self:slideout(0, -config.PH)
elseif effect == "pop" then
self:popIn()
elseif effect == "fade" then
Expand Down
27 changes: 15 additions & 12 deletions RNFactory.lua
Expand Up @@ -49,29 +49,29 @@ mainGroup = RNGroup:new()
stageWidth = 0
stageHeight = 0

function init(width, height, name)
function init(PW, PH, SW, SH , name)

if name == nil then
name = "mainwindow"
end

-- width, height from the SDConfig.lua

MOAISim.openWindow(name, SW, SH)
screen:initWith(PW, PH, SW, SH )

MOAISim.openWindow(name, width, height) --960-by-640
screen:initWith(width, height)
stageWidth = PW
stageHeight = PH

stageWidth = width
stageHeight = height

contentWidth = width
contentHeight = height
contentWidth = PW
contentHeight = PH


RNInputManager.setGlobalRNScreen(screen)
end

-- extra method call to setup the underlying system
init(config.width, config.height)
init(config.PW, config.PH, config.SW, config.SH, config.name)

function showDebugLines()
MOAIDebugLines.setStyle(MOAIDebugLines.PROP_MODEL_BOUNDS, 2, 1, 1, 1)
Expand Down Expand Up @@ -103,6 +103,9 @@ function createImage(filename, params)
parentGroup = params.parentGroup
else
parentGroup = mainGroup
end
if (params.size ~= nil) then
size = params.size
end
end

Expand All @@ -112,7 +115,7 @@ function createImage(filename, params)


local image = RNObject:new()
image:initWith(filename)
image:initWith(filename,size)
screen:addRNObject(image)
image.x = image.originalWidth / 2 + left
image.y = image.originalHeight / 2 + top
Expand Down Expand Up @@ -301,7 +304,7 @@ end

function createRect(x, y, width, height, params)
local parentGroup, top, left
local rgb = { 225, 225, 225 }
local rgb = { 255, 255, 255 }

if params then
parentGroup = params.parentGroup or mainGroups
Expand All @@ -323,7 +326,7 @@ end

function createCircle(x, y, r, params)
local parentGroup, top, left
local rgb = { 225, 225, 225 }
local rgb = { 255, 255, 255 }

if params then
if type(params) == "table" then
Expand Down
6 changes: 2 additions & 4 deletions RNInputManager.lua
Expand Up @@ -307,15 +307,13 @@ end
function onEvent(eventType, idx, x, y, tapCount)

local screen = RNFactory.getCurrentScreen()

local x , y = RNFactory.screen.layer:wndToWorld(x, y)

local currenTarget = screen:getRNObjectWithHighestLevelOn(x, y);
local event = RNEvent:new()
event:initWithEventType(eventType)

event.x = x
event.y = y
local x, y = RNFactory.screen.layer:wndToWorld ( x, y )
event.x, event.y = x, y

local globallisteners = innerInputManager:getGlobalListenersToEvent("touch")

Expand Down
4 changes: 2 additions & 2 deletions RNObject.lua
Expand Up @@ -547,7 +547,7 @@ function RNObject:loadRect(width, height, rgb)
local y = height * .5

local function onDraw()
MOAIGfxDevice.setPenColor(rgb[1] * 0.0044, rgb[2] * 0.0044, rgb[3] * 0.0044, self.alpha)
MOAIGfxDevice.setPenColor(rgb[1] * 0.00392, rgb[2] * 0.00392, rgb[3] * 0.00392, self.alpha)
MOAIDraw.fillRect(-x, -y, x, y)
end

Expand All @@ -568,7 +568,7 @@ end
function RNObject:loadCircle(x, y, r, rgb)
self.name = "shape"
local function onDraw()
MOAIGfxDevice.setPenColor(rgb[1] * 0.0044, rgb[2] * 0.0044, rgb[3] * 0.0044, self.alpha)
MOAIGfxDevice.setPenColor(rgb[1] * 0.00392, rgb[2] * 0.00392, rgb[3] * 0.00392, self.alpha)
MOAIDraw.fillCircle(0, 0, r, 32)
end

Expand Down
4 changes: 2 additions & 2 deletions RNScreen.lua
Expand Up @@ -45,11 +45,11 @@ function RNScreen:setName(name)
self.name = name
end

function RNScreen:initWith(width, height)
function RNScreen:initWith(width, height, SW, SH)
self.width = width
self.height = height
self.viewport = MOAIViewport.new()
self.viewport:setSize(width, height)
self.viewport:setSize( SW, SH)
self.viewport:setScale(width, -height)
self.viewport:setOffset(-1, 1)
self.layer = MOAILayer2D.new()
Expand Down
15 changes: 9 additions & 6 deletions RNUtil.lua
Expand Up @@ -46,12 +46,15 @@ function print_r(t)
print()
end


function memestatus()

local sysMem = collectgarbage("count") * .001

print("Mem: " .. math.floor(sysMem * 1000) * .001 .. "MB \t")
local collect = collectgarbage
local lastCheck = {sysMem = 0}
function memestatus(say)
collect()
local sysMem = collect("count") * .001
if say == true or lastCheck.sysMem ~= sysMem then
lastCheck.sysMem = sysMem
print ("Mem: " .. math.floor(sysMem*1000)*.001 .. "MB \t")
end
end


Expand Down
22 changes: 20 additions & 2 deletions config.lua
Expand Up @@ -14,5 +14,23 @@

module(..., package.seeall)

width = 320
height = 480
local landscape = false --true
local device = "iPad"
local sizes = {}
sizes["iPad"] = {768,1024,384,512}
sizes["iPadreal"] = {768,1024,768,1024}
sizes["iPhone"] = {320,480,503,670}


local sw, sh = MOAIEnvironment.getScreenSize()
if sw ~= 0 then
PW, PH, SW, SH = sw, sh, sw, sh
else
PW, PH, SW, SH = sizes[device][1],sizes[device][2], sizes[device][3], sizes[device][4]
end
sw, sh = nil, nil

if landscape == true then -- flip Widths and Hieghts
PW, PH = PH, PW
SW, SH = SH, SW
end
18 changes: 15 additions & 3 deletions main.lua
Expand Up @@ -11,6 +11,15 @@
-- license based on the Mozilla Public License, with the added requirement that you attribute
-- Moai (http://getmoai.com/) and RapaNui in the credits of your program.
]]
local oprint=print
function print (...)
local prnt = ""
for i = 1,#arg do
if arg[i] == nil then arg[i] = "not defined" end --difference between "nil" and nil.
prnt = prnt .. tostring(arg[i]) .. "\t"
end
return io.stdout:write ( string.format (prnt.."\n" ))
end

require("RNUtil")
require("RNThread")
Expand All @@ -19,9 +28,12 @@ require("RNFactory")
require("RNListeners")
require("RNTransition")
require("RNMainThread")
require("RNPhysics")
require("RNDirector")

local demo = 2
if demo ~= 1 then
require("lua/main")
else
require("RNPhysics")
-- RapaNui demos:

-- Anim
Expand Down Expand Up @@ -116,4 +128,4 @@ require("rapanui-samples/basic/rn-images")
-- These two tests have only text output
--require("rapanui-samples/maps/rn-tiledmap-parser-xml")
--require("rapanui-samples/maps/rn-tiledmap-parser-lua")

end
4 changes: 4 additions & 0 deletions run.sh
@@ -0,0 +1,4 @@
while true
do
/Users/andrew/Documents/MOAI/moai-beta/bin/osx/moai-untz "/Users/andrew/Desktop/MOAIProject/main.lua"
done

0 comments on commit d95247b

Please sign in to comment.