Jump to content

[TOPIC: topicViewTemplate]
[GLOBAL: userSmallPhoto]
Photo

JSON data file performance
Started by Hizashin Feb 16 2017 03:00 PM

- - - - -
1 reply to this topic
json table scrollview
[TOPIC CONTROLS]
[/TOPIC CONTROLS]
[modOptionsDropdown]
[/modOptionsDropdown]
[reputationFilter]
[TOPIC: post.html]
#1

Hizashin

[GLOBAL: userInfoPane.html]
Hizashin
  • Enthusiast

  • 48 posts
  • Corona SDK

I'm using Twine 2 to create a 'choose your own adventure' type story, and I'm outputting the text and structure as a JSON file. I'm reading/decoding the JSON file and then reading from the Lua table (I think, I might be mistaken) with each page render to get the text.

 

The issue I find is that the pause before rendering is noticeable (in the simulator) and the scrollview is sluggish compared to getting text from a Lua table. Can anyone advise how I can improve this? How would I go about copying out relevant data from the JSON file to a Lua table (if that would lead to better performance)? Any tips would be greatly appreciated.

 

I'm not sure if 't' below is a Lua table, or why using that would lead to slower performance.

 

Here's an excerpt of what i have:

local json = require "json"
--Read/decode the json file
local jsonFile = function( filename, base )
if not base then base = system.ResourceDirectory; end
local path = system.pathForFile( filename, base )
local contents
local file = io.open( path, "r" )
if file then
  contents = file:read( "*a" )
  io.close( file )
end
return contents
end
 
-- Create Lua table from JSON file?
local t = json.decode( jsonFile( "data2.json" ) )
 
-- An example of accessing a data value from t
print (t["passages"][2]['text'])

 

Once I have access to the JSON text values I'm rendering them inside a scrollview:

 

local group = display.newGroup()
 
local scrollView = widget.newScrollView
{
   top = display.screenOriginY,
   left = 0,
   width = display.actualContentWidth,
   height = display.actualContentHeight,
   scrollWidth = display.actualContentWidth,
   scrollHeight = 8000,
   backgroundColor = { 0.05, 0.05, 0.05 },
   --hideBackground = true,
   horizontalScrollDisabled = true,
   friction = 0.95,
   hideScrollBar = true,
   bottomPadding = 30
}
 
local options = 
{
   text = (t["passages"][#num]["text"]),
   width = display.actualContentWidth-30,
   font = native.newFont( "Paciencia-Regular", 32 ),
   fontSize = 15,
   align = "left",
   parent = group
}
 
local paragraph = display.newText( options )
paragraph.anchorX = 0.5
paragraph.anchorY = 0
paragraph.x = display.actualContentWidth/2
paragraph.y = 380
paragraph:setFillColor( 0.95, 0.95, 0.95 )
scrollView:insert( paragraph )


[TOPIC: post.html]
#2

nick_sherman

[GLOBAL: userInfoPane.html]
nick_sherman
  • Corona Geek

  • 1,093 posts
  • Corona SDK

So are you using json.decode every time you draw a new scrollView, or just once at the beginning?

 

't' is a lua table, but if you're re-populating it each time that might cause a delay. Might be better to import all your text into lua tables right at the beginning.




[topic_controls]
[/topic_controls]



Also tagged with one or more of these keywords: json, table, scrollview