Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
M
mycard
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Locked Files
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Security & Compliance
Security & Compliance
Dependency List
License Compliance
Packages
Packages
List
Container Registry
Analytics
Analytics
CI / CD
Code Review
Insights
Issues
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
xiaoye
mycard
Commits
8c2803a7
Commit
8c2803a7
authored
Nov 23, 2011
by
神楽坂玲奈
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fps初步
parent
aab554d9
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
91 additions
and
19 deletions
+91
-19
lib/fpstimer.rb
lib/fpstimer.rb
+70
-0
lib/main.rb
lib/main.rb
+2
-1
lib/scene.rb
lib/scene.rb
+19
-18
No files found.
lib/fpstimer.rb
0 → 100644
View file @
8c2803a7
class
FPSTimer
FPS_COUNT
=
10
attr_accessor
:fps
attr_reader
:real_fps
,
:total_skip
attr_reader
:count_sleep
# +fps+ is the number of frames per second that you want to keep,
# +accurary+ is the accurary of sleep/SDL.delay in milisecond
def
initialize
(
fps
=
60
,
accurary
=
10
,
skip_limit
=
15
)
@fps
=
fps
@accurary
=
accurary
/
1000.0
@skip_limit
=
skip_limit
reset
end
# reset timer, you should call just before starting loop
def
reset
@old
=
get_ticks
@skip
=
0
@real_fps
=
@fps
@frame_count
=
0
@fps_old
=
@old
@count_sleep
=
0
@total_skip
=
0
end
# execute given block and wait
def
wait_frame
now
=
get_ticks
nxt
=
@old
+
(
1.0
/
@fps
)
if
nxt
>
now
||
@skip
>
@skip_limit
yield
@skip
=
0
wait
(
nxt
)
@old
=
nxt
else
@skip
+=
1
@total_skip
+=
1
@old
=
get_ticks
end
calc_real_fps
end
private
def
wait
(
nxt
)
while
nxt
>
get_ticks
+
@accurary
sleep
(
@accurary
-
0.005
)
@count_sleep
+=
1
end
while
nxt
>
get_ticks
# busy loop, do nothing
end
end
def
get_ticks
SDL
.
get_ticks
/
1000.0
end
def
calc_real_fps
@frame_count
+=
1
if
@frame_count
>=
FPS_COUNT
@frame_count
=
0
now
=
get_ticks
@real_fps
=
FPS_COUNT
/
(
now
-
@fps_old
)
@fps_old
=
now
end
end
end
\ No newline at end of file
lib/main.rb
View file @
8c2803a7
...
@@ -43,7 +43,8 @@ require_relative 'window'
...
@@ -43,7 +43,8 @@ require_relative 'window'
require_relative
'window_list'
require_relative
'window_list'
require_relative
'window_user'
require_relative
'window_user'
require_relative
'scene_title'
require_relative
'scene_title'
require_relative
'fpstimer'
$fpstimer
=
FPSTimer
.
new
$scene
=
Scene_Title
.
new
$scene
=
Scene_Title
.
new
while
$scene
while
$scene
$scene
.
main
$scene
.
main
...
...
lib/scene.rb
View file @
8c2803a7
...
@@ -14,7 +14,6 @@ class Scene
...
@@ -14,7 +14,6 @@ class Scene
start
start
while
$scene
==
self
while
$scene
==
self
update
update
sleep
0.01
end
end
terminate
terminate
end
end
...
@@ -49,24 +48,26 @@ class Scene
...
@@ -49,24 +48,26 @@ class Scene
# ● 更新画面
# ● 更新画面
#--------------------------------------------------------------------------
#--------------------------------------------------------------------------
def
update
def
update
while
event
=
Event
.
poll
while
event
=
Event
.
poll
handle
(
event
)
handle
(
event
)
end
end
#@fps.clear(0,0,100,24)
#@fps.clear(0,0,100,24)
#@font.draw_blended_utf8(@fps.contents, @fpscount, 160, 12, 0x00,0x00,0x00)
#@font.draw_blended_utf8(@fps.contents, @fpscount, 160, 12, 0x00,0x00,0x00)
#@fpscount += 1
#@fpscount += 1
$screen
.
put
(
@background
,
0
,
0
)
$fpstimer
.
wait_frame
do
@windows
.
each
do
|
window
|
$screen
.
put
(
@background
,
0
,
0
)
if
window
.
angle
.
zero?
@windows
.
each
do
|
window
|
if
window
.
angle
.
zero?
Surface
.
blit
(
window
.
contents
,
*
window
.
viewport
,
$screen
,
window
.
x
,
window
.
y
)
if
window
.
contents
&&
window
.
visible
Surface
.
blit
(
window
.
contents
,
*
window
.
viewport
,
$screen
,
window
.
x
,
window
.
y
)
if
window
.
contents
&&
window
.
visible
else
else
contents
=
window
.
contents
.
transform_surface
(
0x66000000
,
180
,
1
,
1
,
0
)
contents
=
window
.
contents
.
transform_surface
(
0x66000000
,
180
,
1
,
1
,
0
)
Surface
.
blit
(
contents
,
*
window
.
viewport
,
$screen
,
window
.
x
,
window
.
y
)
if
window
.
contents
&&
window
.
visible
Surface
.
blit
(
contents
,
*
window
.
viewport
,
$screen
,
window
.
x
,
window
.
y
)
if
window
.
contents
&&
window
.
visible
#Surface.transform_blit(window.contents,$screen,0,1,1,100,100,100,100,Surface::TRANSFORM_AA)#,0,0)
#Surface.transform_blit(window.contents,$screen,0,1,1,100,100,100,100,Surface::TRANSFORM_AA)#,0,0)
end
end
#$screen.put(window.contents, window.x, window.y) if window.contents && window.visible
#$screen.put(window.contents, window.x, window.y) if window.contents && window.visible
end
end
$screen
.
update_rect
(
0
,
0
,
0
,
0
)
$screen
.
update_rect
(
0
,
0
,
0
,
0
)
end
end
end
def
handle
(
event
)
def
handle
(
event
)
case
event
case
event
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment