Skip to content

Commit bede8ba

Browse files
committed
Half working version.
1 parent 55808f4 commit bede8ba

File tree

3 files changed

+70
-42
lines changed

3 files changed

+70
-42
lines changed

pc_lua_version/app/scripts/demo_simulation.lua

Lines changed: 38 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,7 @@ return Class {
249249
self.ubob_frame = (self.ubob_frame+1%screen_size.ANIM_STRIPEb)
250250
self.ubob_offset_phase = self.ubob_offset_phase+120.0*self.dt
251251
self.ubob_scale = self.ubob_scale+self.dt*1.5
252-
return not has_ended()
252+
return not has_ended()
253253
end,
254254

255255
clear_playfield = function(self, from_top)
@@ -292,40 +292,40 @@ return Class {
292292
end,
293293

294294
render_demo_text = function(self)
295-
local text_duration = #(font_desc.demo_string[self.current_text_idx + 1])*0.05
296-
local fade_duration = 0.2
297-
if self.current_text_idx==-1 or self.text_display_timer>text_duration then
298-
self.text_display_timer = 0.0
299-
self.current_text_idx = self.current_text_idx+1
300-
if self.current_text_idx>=#font_desc.demo_string then
301-
self.current_text_idx = 0
302-
end
303-
local text_string = font_desc.demo_string[self.current_text_idx]
304-
self.text_pixel_w = self.font_writer_blit(self.pictures['font_sans_serif'], self.text_buffer, 0, 0, text_string)
305-
end
306-
self.text_display_timer = self.text_display_timer+self.dt*0.5
307-
local opacity
308-
if self.text_display_timer<fade_duration then
309-
opacity = Clamp(RangeAdjust(self.text_display_timer, 0.0, fade_duration, 0.0, 1.0), 0.0, 1.0)
310-
elseif self.text_display_timer>text_duration-fade_duration then
311-
opacity = Clamp(RangeAdjust(self.text_display_timer, text_duration-fade_duration, text_duration, 1.0, 0.0), 0.0, 1.0)
312-
else
313-
opacity = 1.0
314-
end
315-
opacity = Quantize(opacity, 8)
316-
local dest_rect = self.text_buffer:GetRect()
317-
dest_rect:SetHeight(screen_size.DISPL_HEIGHT3)
318-
local dest_rect_offset = dest_rect:Offset(0, screen_size.DISPL_HEIGHT1)
319-
dest_rect_offset:SetHeight(screen_size.DISPL_HEIGHT3+1)
320-
self.screen_pic:SetFillColorRGBA(screen_size.COLOUR_PURPLE.r*1.5, screen_size.COLOUR_PURPLE.g*1.5, screen_size.COLOUR_PURPLE.b*1.5, 1.0)
321-
self.screen_pic:SetFillMode(hg.BrushSolid)
322-
self.screen_pic:SetPenMode(hg.PenNone)
323-
self.screen_pic:DrawRect(dest_rect_offset.sx, dest_rect_offset.sy, dest_rect_offset.ex, dest_rect_offset.ey)
324-
self.screen_pic:Blit(self.text_buffer, dest_rect, hg.IntVector2(math.floor((screen_size.WIDTH3-self.text_pixel_w)/2.0), screen_size.DISPL_HEIGHT1+1))
325-
if opacity<1.0 then
326-
self.screen_pic:SetFillColorRGBA(screen_size.COLOUR_PURPLE.r*1.5, screen_size.COLOUR_PURPLE.g*1.5, screen_size.COLOUR_PURPLE.b*1.5, 1.0-opacity)
327-
self.screen_pic:DrawRect(dest_rect_offset.sx, dest_rect_offset.sy, dest_rect_offset.ex, dest_rect_offset.ey)
328-
end
295+
-- local text_duration = #(font_desc.demo_string[self.current_text_idx + 1])*0.05
296+
-- local fade_duration = 0.2
297+
-- if self.current_text_idx==-1 or self.text_display_timer>text_duration then
298+
-- self.text_display_timer = 0.0
299+
-- self.current_text_idx = self.current_text_idx+1
300+
-- if self.current_text_idx>=#font_desc.demo_string then
301+
-- self.current_text_idx = 0
302+
-- end
303+
-- local text_string = font_desc.demo_string[self.current_text_idx]
304+
-- self.text_pixel_w = self:font_writer_blit(self.pictures['font_sans_serif'], self.text_buffer, 0, 0, text_string)
305+
-- end
306+
-- self.text_display_timer = self.text_display_timer+self.dt*0.5
307+
-- local opacity
308+
-- if self.text_display_timer<fade_duration then
309+
-- opacity = Clamp(RangeAdjust(self.text_display_timer, 0.0, fade_duration, 0.0, 1.0), 0.0, 1.0)
310+
-- elseif self.text_display_timer>text_duration-fade_duration then
311+
-- opacity = Clamp(RangeAdjust(self.text_display_timer, text_duration-fade_duration, text_duration, 1.0, 0.0), 0.0, 1.0)
312+
-- else
313+
-- opacity = 1.0
314+
-- end
315+
-- opacity = Quantize(opacity, 8)
316+
-- local dest_rect = self.text_buffer:GetRect()
317+
-- dest_rect:SetHeight(screen_size.DISPL_HEIGHT3)
318+
-- local dest_rect_offset = dest_rect:Offset(0, screen_size.DISPL_HEIGHT1)
319+
-- dest_rect_offset:SetHeight(screen_size.DISPL_HEIGHT3+1)
320+
-- self.screen_pic:SetFillColorRGBA(screen_size.COLOUR_PURPLE.r*1.5, screen_size.COLOUR_PURPLE.g*1.5, screen_size.COLOUR_PURPLE.b*1.5, 1.0)
321+
-- self.screen_pic:SetFillMode(hg.BrushSolid)
322+
-- self.screen_pic:SetPenMode(hg.PenNone)
323+
-- self.screen_pic:DrawRect(dest_rect_offset.sx, dest_rect_offset.sy, dest_rect_offset.ex, dest_rect_offset.ey)
324+
-- self.screen_pic:Blit(self.text_buffer, dest_rect, hg.IntVector2(math.floor((screen_size.WIDTH3-self.text_pixel_w)/2.0), screen_size.DISPL_HEIGHT1+1))
325+
-- if opacity<1.0 then
326+
-- self.screen_pic:SetFillColorRGBA(screen_size.COLOUR_PURPLE.r*1.5, screen_size.COLOUR_PURPLE.g*1.5, screen_size.COLOUR_PURPLE.b*1.5, 1.0-opacity)
327+
-- self.screen_pic:DrawRect(dest_rect_offset.sx, dest_rect_offset.sy, dest_rect_offset.ex, dest_rect_offset.ey)
328+
-- end
329329
end,
330330

331331
font_writer_blit = function(self, font_picture, dest_picture, x, y, text_string)
@@ -342,11 +342,11 @@ return Class {
342342
end
343343
local i = 0
344344
local cur_x = x
345-
y = y+screen_size.DISPL_HEIGHT1
346-
local text_string = list(text_string)
345+
y = y + screen_size.DISPL_HEIGHT1
346+
local text_string = stringToList(text_string)
347347
dest_picture.ClearRGBA(screen_size.COLOUR_PURPLE.r*1.5, screen_size.COLOUR_PURPLE.g*1.5, screen_size.COLOUR_PURPLE.b*1.5, 1.0)
348348
while i<#text_string do
349-
if text_string[i]==' ' then
349+
if text_string[i + 1] == ' ' then
350350
cur_x = cur_x+4
351351
end
352352
local glyph_index = font_glyph_find_index(text_string[i], font_desc.tiny_font['glyph'])

pc_lua_version/app/scripts/main.lua

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,17 @@ hg = require('harfang')
66
require('app/scripts/utils')
77
local DemoSimulation = require('app/scripts/demo_simulation')
88

9+
ASYNC_MODE = false
10+
911
main = function()
1012
local pc_screen_windowed = true
1113
local pc_screen_width = 1280
1214
local pc_screen_height = 720
1315

1416
local plus = hg.GetPlus()
15-
plus:CreateWorkers()
17+
if ASYNC_MODE then
18+
plus:CreateWorkers()
19+
end
1620

1721
pc_screen_windowed = false
1822

@@ -41,7 +45,17 @@ main = function()
4145

4246
plus:RenderInit(pc_screen_width, pc_screen_height) -- , 1, w_mode)
4347
plus:AudioInit()
44-
local egl = plus:GetRendererAsync()
48+
local egl
49+
local al
50+
51+
if ASYNC_MODE then
52+
egl = plus:GetRendererAsync()
53+
al = plus:GetMixerAsync()
54+
else
55+
egl = plus:GetRenderer()
56+
al = plus:GetMixer()
57+
end
58+
4559
local font = hg.RasterFont('@core/fonts/default.ttf', 48, 512)
4660

4761
local demo = DemoSimulation(demo_screen_width, demo_screen_height)
@@ -53,7 +67,7 @@ main = function()
5367

5468
local res = egl:CreateTexture(demo_screen_tex, demo.screen_pic)
5569
print('CreateTexture() returned ', res)
56-
local al = plus:GetMixerAsync()
70+
5771
al:Open()
5872
local channel_state = hg.MixerChannelState(0, 1, hg.MixerRepeat)
5973
al:Stream('res/music_loop.ogg', channel_state)
@@ -91,7 +105,11 @@ main = function()
91105

92106
demo:render_demo_text()
93107

94-
egl:BlitTexture(demo_screen_tex, hg.BinaryData(demo.screen_pic:GetData()), demo_screen_width, demo_screen_height)
108+
if ASYNC_MODE then
109+
egl:BlitTexture(demo_screen_tex, hg.BinaryData(demo.screen_pic:GetData()), demo_screen_width, demo_screen_height)
110+
else
111+
egl:BlitTexture(demo_screen_tex, demo.screen_pic) -- , demo_screen_width, demo_screen_height)
112+
end
95113

96114
if pc_screen_windowed then
97115
plus:Quad2D(0, 0, 0, pc_screen_height, pc_screen_width, pc_screen_height, pc_screen_width, 0, hg.Color.White, hg.Color.White, hg.Color.White, hg.Color.White, demo_screen_tex, overscan_factor.x, overscan_factor.y, overscan_factor.z, overscan_factor.w)

pc_lua_version/app/scripts/utils.lua

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,13 @@ mapValueToArray = function(val, in_lower, in_upper, mapping_array)
2121
local floor_pos = math.floor(array_pos)
2222
return mapping_array[floor_pos + 1]*(ceil_pos-array_pos) + mapping_array[ceil_pos + 1]*(1.0-(ceil_pos-array_pos))
2323
end
24+
25+
stringToList = function(str)
26+
local t = {}
27+
for i = 1, #str do
28+
t[i] = str:sub(i, i)
29+
end
30+
return t
31+
end
32+
33+

0 commit comments

Comments
 (0)