Commit Graph

43 Commits

Author SHA1 Message Date
Hajime Hoshi
237498e51f
ui: Add an optional function Draw function to Game interface (#1107)
This change adds an optional function Draw to the Game interface.
With Draw function, the game logic and rendering are separate.
There are some benefits:

  * The API is clearer and easier to understand.
  * When TPS < FPS, smoother rendering can be performed without
    changing the game logic depending on TPS.
  * Porting to XNA, which has separate functions Update and Draw,
    would be a little easier.

Draw is optional due to backward compatibility. Game interface was
already used before v1.11.x in mobile packages, and adding a
function would break existing code unfortunately. Then, we adopted
switching the behavior based on whether Draw is implemented or not
by type assertions.

IsDrawingSkipped will always return false when Draw is implemented.

Fixes #1104
2020-03-24 12:01:37 +09:00
Hajime Hoshi
c927d33457 mobile/ebitenmobileview: Use the common uiContext for layouting
This means that the whole offscreen is cleared correctly.

This change is a little breaking change: SetScreenSize or other
functions no longer works on ebitenmobile. Use Layout instead.

Fixes #1019
2020-02-11 19:40:47 +09:00
Hajime Hoshi
024fc48647 Refactoring: Add init.go 2020-02-11 11:14:19 +09:00
Hajime Hoshi
b3bdf51905
graphicscommand: Return the error immediately (#1060)
Now grpahicscommand saves the error and shows the error after a
while. This was good to simplify the API but was the cause to hide
some issues.

This change fixes all the errors to be returned immediately, and
buffer this in the ebiten package instead.

Fixes #971
2020-01-19 01:18:56 +09:00
Hajime Hoshi
4c8137ccf5 mipmap: Bug fix: Use more negative mipmaps when float precision is low
Fixes #1044
2020-01-08 02:06:36 +09:00
Hajime Hoshi
982b7d6ddc driver: Let UI have Graphics
Now UIs own the implementation of Graphics.

Updates #1026
2020-01-03 18:32:27 +09:00
Hajime Hoshi
662a22461d run: Bug fix: The screen can be nil in the initial state
Fixes #1039
2019-12-29 23:14:59 +09:00
Hajime Hoshi
9ed8279fc8 driver: Add interface Window 2019-12-25 00:24:21 +09:00
Hajime Hoshi
1d9c00688c ui: Panic if Layout returns non-positive numbers 2019-12-23 04:43:04 +09:00
Hajime Hoshi
049aa552d4 ui: Add SetWindowResizable
This change also fixes example/windowsize.

Fixes #320
2019-12-22 19:26:04 +09:00
Hajime Hoshi
812a29bf07 ui: Refactoring: theUIContext is always non-nil 2019-12-22 18:53:23 +09:00
Hajime Hoshi
7d56e4335e ui: Add RunGame, WindowSize and SetWindowSize
This change introduces the new APIs RunGame, WindowSize and
SetWindowSize. These new APIs hides the notion of 'scale', and is
more flexible with the outside size change. This means that we can
introduce a resizable window.

This change also adds -legacy flag to examples/windowsize. If the
flag is off, the new APIs are used.

This change deprecates these functions since the notion of 'scale'
is deprecated:

  * ScreenScale
  * ScreenSizeInFullscreen
  * SetScreenScale
  * SetScreenSize

Fixes #943, #571
Updates #320
2019-12-22 03:35:31 +09:00
Hajime Hoshi
f3712a7e62 ui: Add comments about scaleForWindow 2019-12-20 03:59:32 +09:00
Hajime Hoshi
ba0279ebe3 ui: Bug fix: Stop the loop of window-size recalculation 2019-12-20 01:56:27 +09:00
Hajime Hoshi
6a8013ed37 ui: Reduce arguments from newUIContext 2019-12-16 11:12:38 +09:00
Hajime Hoshi
664cf62a29 ui: Reduce members from uiContext 2019-12-16 02:10:58 +09:00
Hajime Hoshi
97ddef0047 ui: Protect defaultGame's memers with mutex 2019-12-16 01:44:55 +09:00
Hajime Hoshi
46a7ae6175 ui: Define and use defaultGame
This is a pareparation for Game interface and RunGame.

Updates #943
2019-12-16 01:21:16 +09:00
Hajime Hoshi
12a13892cd ui: Protect uiContext.scaleForWindow by mutex 2019-12-15 20:15:13 +09:00
Hajime Hoshi
bda11b0e17 driver: Add UI.SetWindowSize and UIContext.Layout
This is a preparation to introduce RunGame function.

Updates # 943 (Fix this line before committing)
2019-12-15 02:29:43 +09:00
Hajime Hoshi
8e9f5b9535 driver: Remove Suspend/ResumeAudio from UIContext 2019-12-08 16:17:02 +09:00
Hajime Hoshi
42056c2d61 restorable: Refactoring: Remove Clear
Fill now fills the whole texture.
2019-12-02 03:03:07 +09:00
Hajime Hoshi
69c781a03d ui: Refactoring 2019-11-25 02:26:12 +09:00
Hajime Hoshi
79b32c7601 graphics: Add buffered package
Moved the command queue to the package.
2019-09-21 22:34:37 +09:00
Hajime Hoshi
1c2c932c6c graphics: Remove MakeVolatile/IsVolatile 2019-09-21 14:53:52 +09:00
Hajime Hoshi
52900fac79 Move back driver getters to ebiten package 2019-09-03 01:46:11 +09:00
Hajime Hoshi
3646e7930d graphics: Bug fix: the flag and the enqueueing operation must be protected by a same mutex
It was theoretically possible that an item was enqueued even
though the flag said it should not.
2019-08-25 21:22:54 +09:00
Hajime Hoshi
d2312f1450 shareable: Lock before BeginFrame
This make package shareable more consistent. The mutex is lock
after EndFrame and before BeginFrame, and the similar rule will be
applied at launching (BeginFrame unlocks the lock in any cases).

Instead, package ebiten queues image operations if BeginFrame and
doesn't create provisional non-shared images. This should improve
performance at launching since this reduces the number of draw
calls, especifally for creating new images.

Updates #879.
Updates #921.
2019-08-25 18:12:04 +09:00
Hajime Hoshi
b53279b1e1 shareable: Remove InitializeGraphicsDriverState 2019-08-25 17:28:59 +09:00
Hajime Hoshi
e931494c66 shareable: Allocate the screen framebuffer image lazily
This improves consistency.
2019-08-25 00:43:29 +09:00
Hajime Hoshi
ef56d0a535 Refactoring: isRunning -> isImageAvailable 2019-08-25 00:14:37 +09:00
Hajime Hoshi
4373bd8b89 restorable: Unify locks with shareable's backendsM and fix the deadlock
This change should make Image operations cuncurrent safe.

Updates #913
Fixes #915
2019-08-13 00:49:47 +09:00
Hajime Hoshi
de915a1736 Move driver getters to graphicsdriver/uidriver packages
This enables to add internal functions to these packages so that
the driver selector logics can be modified.
2019-08-01 00:40:59 +09:00
Hajime Hoshi
2d079b123f restorable: Add ResetRestoringState to reset the state
After Fill command, the image doesn't have to keep the restoring
information. Now Fill command is as same as DrawTriangles, there
is no way for restorable.Image to know whether it can reset the
state or not. ResetRestoringState clears the state explicitly.
2019-07-20 14:04:02 +09:00
Hajime Hoshi
0dc1d0eba5 graphics: Clear/Fill is now implemented with DrawImage
Only clearing the screen still requires the special method.
2019-07-20 04:34:42 +09:00
Hajime Hoshi
7a399c1b82 shareable: Update page sizes dynamically
Also, all the images cannot use the shareable backends before the
game starts, but it is expected that read-only images will use
shareable backends later.

Fixes #879
2019-06-22 23:05:28 +09:00
Hajime Hoshi
b41a333230 restorable: Reland: Refactoring 2019-05-26 22:16:25 +09:00
Hajime Hoshi
da4fabeaa5 Revert "restorable: Refactoring"
This reverts commit 3c0cd47b1f.

Reason: Crash on macOS
2019-05-26 21:30:08 +09:00
Hajime Hoshi
3c0cd47b1f restorable: Refactoring 2019-05-26 21:24:44 +09:00
Hajime Hoshi
fcb5554aa1 driver: Add Graphics.NeedsRestoring 2019-05-26 19:46:12 +09:00
Hajime Hoshi
b99f4c61b5 graphicsdriver/metal: Make (*Driver).Flush do nothing 2019-04-20 16:50:40 +09:00
Hajime Hoshi
61156dd90e graphics: Rename pixelsToSet -> pendingPixels 2019-04-11 14:02:41 -07:00
Hajime Hoshi
f6367308fc driver: Rename GraphicsContext -> UIContext 2019-04-08 23:28:08 -04:00