Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
boytacean
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
João Magalhães
boytacean
Commits
1753a825
Verified
Commit
1753a825
authored
1 year ago
by
João Magalhães
Browse files
Options
Downloads
Patches
Plain Diff
chore: improved performance of sdl2
parent
b48963b2
No related branches found
No related tags found
1 merge request
!36
Support for Python
Pipeline
#3646
passed
1 year ago
Stage: build
Stage: test
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/python/boytacean/gb.py
+1
-1
1 addition, 1 deletion
src/python/boytacean/gb.py
src/python/boytacean/graphics.py
+25
-22
25 additions, 22 deletions
src/python/boytacean/graphics.py
with
26 additions
and
23 deletions
src/python/boytacean/gb.py
+
1
−
1
View file @
1753a825
...
...
@@ -223,7 +223,7 @@ This is a [Game Boy](https://en.wikipedia.org/wiki/Game_Boy) emulator built usin
self
.
_video
.
save_frame
(
self
.
image
(),
self
.
_frame_index
)
self
.
_video
.
compute_next
(
self
.
_frame_index
)
#@TODO: this should be sample, meaning that not every
#
@TODO: this should be sample, meaning that not every
# single frame is sent to the display (performance)
if
self
.
_display
!=
None
:
from
.graphics
import
Display
...
...
This diff is collapsed.
Click to expand it.
src/python/boytacean/graphics.py
+
25
−
22
View file @
1753a825
...
...
@@ -18,6 +18,7 @@ class Display:
_height
:
int
=
DISPLAY_HEIGHT
_title
:
str
=
"
Boytacean
"
_window
:
Union
[
Window
,
None
]
=
None
_renderer
:
Union
[
Renderer
,
None
]
=
None
def
__init__
(
self
,
...
...
@@ -29,25 +30,27 @@ class Display:
self
.
_height
=
height
self
.
_title
=
title
self
.
_window
=
None
self
.
_renderer
=
None
self
.
build
()
def
build
(
self
):
init_sdl
()
self
.
_window
=
Window
(
self
.
_title
,
size
=
(
self
.
_width
,
self
.
_height
))
self
.
_window
.
show
()
self
.
_renderer
=
Renderer
(
self
.
_window
)
def
render_frame
(
self
,
frame_buffer
:
bytes
):
if
not
self
.
_window
:
raise
RuntimeError
(
"
Window not initialized
"
)
if
not
self
.
_renderer
:
raise
RuntimeError
(
"
Renderer not initialized
"
)
# we consider that every time there's a request for a new
# frame draw the queue of SDL events should be flushed
events
=
get_events
()
for
event
in
events
:
if
event
.
type
==
SDL_QUIT
:
running
=
False
# @TODO need to destroy the engine
break
# @TODO: this should not be build every single frame
renderer
=
Renderer
(
self
.
_window
)
pass
surface
=
SDL_CreateRGBSurfaceFrom
(
frame_buffer
,
...
...
@@ -55,23 +58,23 @@ class Display:
DISPLAY_HEIGHT
,
24
,
DISPLAY_WIDTH
*
3
,
0x000000
FF
,
0x0000
FF
00
,
0x00
FF
0000
,
0x000000
ff
,
0x0000
ff
00
,
0x00
ff
0000
,
0x0
,
)
texture
=
SDL_CreateTextureFromSurface
(
renderer
.
sdlrenderer
,
surface
.
contents
)
# @TODO: not sure this clear is required
renderer
.
clear
(
Color
(
0
,
0
,
0
))
SDL_RenderCopy
(
renderer
.
sdlrenderer
,
texture
,
None
,
SDL_Rect
(
0
,
0
,
DISPLAY_WIDTH
,
DISPLAY_HEIGHT
),
texture
=
SDL_CreateTextureFromSurface
(
self
.
_renderer
.
sdlrenderer
,
surface
.
contents
)
renderer
.
present
()
# @TODO: need to destroy latter on
# SDL_DestroyTexture(texture)
# SDL_FreeSurface(surface)
try
:
SDL_RenderCopy
(
self
.
_renderer
.
sdlrenderer
,
texture
,
None
,
SDL_Rect
(
0
,
0
,
DISPLAY_WIDTH
,
DISPLAY_HEIGHT
),
)
self
.
_renderer
.
present
()
finally
:
SDL_DestroyTexture
(
texture
)
SDL_FreeSurface
(
surface
)
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment