Commit Graph

55 Commits

Author SHA1 Message Date
Jonas Kulla 577f606dac Tilemap: Factor out flash tile code
This will be reused later in TilemapVX.
2014-10-26 20:00:56 +01:00
Jonas Kulla 520162f36a Use safe way to get at a vector's data pointer
&std::vector<C>[0] is not guaranteed to not throw if the
vector is empty. Better safe than sorry.
2014-10-09 19:02:29 +02:00
Jonas Kulla 9758e660c4 Tilemap/VX: Ensure proxy objects don't outlive their parents
Either of these would previously crash (same for VX):

tm = Tilemap.new
at = tm.autotiles
tm = nil
GC.start
at[0] = Bitmap.new(1, 1)

tm = Tilemap.new
at = tm.autotiles
tm.dispose
at[0] = Bitmap.new(1, 1)

Funnily, this makes RMXP itself crash too, but crashing is
never acceptable except for possibly resource exhaustion.
2014-09-26 18:21:50 +02:00
Jonas Kulla 81ac0780f8 Revert Disposable concept back into core
Pretty much a revert of
e858bbdcf5.

We need this in core to properly implement F12 reset.
2014-09-23 21:12:58 +02:00
Jonas Kulla d8bb6aa2fc Replicate RMVX/VXA's broken sprite Z sorting implementation
Fixes Window_NameBox visual appearance in Skyborn.

Also nuke the second SceneElement constructor that has been
obsolete since the Tilemap mapViewport rewrite.
2014-08-31 01:10:32 +02:00
Jonas Kulla 28421a0ce5 Tilemap: Remove RGSS2 viewport setter
This class is not used in RGSS2 at all.
2014-08-28 15:37:04 +02:00
Jonas Kulla 724d52f61e Tilemap: Finally get rid of that terrible name 'ScanRow'
Replacement: ZLayer
I'd really have loved to have used something alluding to physical
roof tiles (as that's the closest image I have to them), but without
reusing the word "tiles".. yeah, impossible.
2014-08-17 03:58:01 +02:00
Jonas Kulla 4742226e7c Tilemap: Fix typo 2014-08-15 15:20:32 +02:00
Jonas Kulla d128375d62 DisposeWatch: Make private and constify members 2014-08-12 21:41:59 +02:00
Jonas Kulla e858bbdcf5 Lift 'Disposable' concept from core into bindings
Instead of replicating the RGSS Disposable interface in C++
and merely binding it, redefine the 'disposed' state as the
entire core object being deleted (and the binding object's
private pointer being null).

This makes the behavior more accurate in regard to RMXP.
It is now for example possible to subclass disposable classes
and access their 'dispose'/'disposed?' methods without
initializing the base class first (because the internal pointer
is simply null before initialization). Accessing any other
base methods will still raise an exception.

There are some quirks and irregular behavior in RMXP; eg.
most nullable bitmap attributes of disposable classes
(Sprite, Plane etc.) can still be queried afterwards, but
some cannot (Tilemap#tileset), and disposing certain
attributes crashes RMXP entirely (Tilemap#autotiles[n]).
mkxp tries to behave as close possible, but will be more
lenient some circumstances.

To the core, disposed bitmap attributes will look
identically to null, which slightly diverges from RMXP
(where they're treated as still existing, but aren't drawn).
The Disposable interface has been retained containing a
single signal, for the binding to inform core when
objects are disposed (so active attributes can be set to null).
2014-08-09 21:21:38 +02:00
Jonas Kulla 813130fbf6 More size_t fixes 2014-07-19 02:58:57 +02:00
Jonas Kulla b8d861b4cd gl-util.h: Remove wrappers for things abstracted via GLMeta 2014-07-16 05:22:43 +02:00
Jonas Kulla bae977d4ab GLMeta: "Finish" -> "End" 2014-07-16 04:53:08 +02:00
Jonas Kulla a26c73930d GLMeta: Add framebuffer blitting support 2014-07-16 04:48:40 +02:00
Jonas Kulla 97708d25b6 Tilemap: Reduce a few unnecessary blits
No need to replicate static autotiles if we're not animating
at all.
2014-07-13 14:05:56 +02:00
Jonas Kulla efb2fd2695 GLMeta: Add vertex array object support 2014-07-13 14:05:12 +02:00
Jonas Kulla b73461721c Add meta path with fallback for EXT_unpack_subimage parameters 2014-07-13 05:51:04 +02:00
Jonas Kulla a541cb1205 Some RGSS2/RGSS3 compile fixes 2014-07-13 05:34:18 +02:00
Jonas Kulla 91aefdc17a Tilemap: Fix map wrap around 2014-07-11 08:43:39 +02:00
Jonas Kulla caae9c5689 Wrap IBO index type into one definition
Makes it easier to switch between types (eg. 32 -> 16 bit).
2014-07-11 02:09:53 +02:00
Jonas Kulla 295e0e5b15 Tilemap: Rewrite to only process and render visible region
Previously, on creation, we would parse the entire map data,
translating it into and uploading vertices once, then rendering
the entire map on every draw (to keep the draw calls minimal).
This worked great for smaller and medium sized maps, but starting
with larger maps (200x200+) it doesn't scale as the GPUs vertex
processing/culling is overwhelmed by the amount of data each frame.

This rewrite instead changes the strategy to only processing and
uploading a small subregion of the map (the currently visible part)
and regenerating all buffers if this subregion changes. The amount
of data transferred is small enough that it can be done every frame
without causing lag.

The changes also have the convenient side effect that we no longer
require 32 bit indices in mkxp, easing the road to possible GLES2
support in the future.
2014-07-11 02:00:30 +02:00
Jonas Kulla 56226c40c6 Tilemap: Use vertex shader based autotile animation strategy
Previously, we would just stuff the entire tilemap vertex data
four times into the buffers, with only the autotile vertices
offset according to the animation frame. This meant we could
prepare the buffers once, and then just bind a different offset
for each animation frame without any shader changes, but it also
lead to a huge amount of data being duplicated (and blowing up
the buffer sizes).

The new method only requires one buffer, and instead animates by
recognizing vertices belonging to autotiles in a custom vertex
shader, which offsets them on the fly according to the animation
index.

With giant tilemaps, this method would turn out to be a little
less efficient, but considering the Tilemap is planned to be
rewritten to only hold the range of tiles visible on the screen
in its buffers, the on the fly offsetting will become neglient,
while at the same time the amount of data we have to send to the
GPU everytime the tilemap is updated is greatly reduced; so a
net win in the end.
2014-07-06 19:44:19 +02:00
Jonas Kulla 6c481e5eb8 Eliminate GLEW dependency
GL entrypoint resolution is now done manually. This has a couple
immediate benefits, such as not having to retrieve hundreds of
functions pointers that we'll never use. It's also nice to have
an exact overview of all the entrypoints used by mkxp.

This change allows mkxp to run fine with core contexts, not sure
how relevant that is going to be in the future.

What's noteworthy is that  _all_ entrypoints, even the ones core
in 1.1 and guaranteed to be in every libGL, are resolved
dynamically.
This has the added benefit of not having to link directly against
libGL anymore, which also cleans up the output of `ldd` quite
a bit (SDL2 loads most system deps dynamically at runtime).

GL headers are still required at build time.
2014-06-13 18:46:45 +02:00
Jonas Kulla 2cc2ebca31 GLState: Get rid of GL_TEXTURE_2D enable/disable
This bit was deprecated/removed in core GL.

There was only one place where this was used (flash tiles
in Tilemap), and since the full shader rewrite, it was
effectively a no-op anyway (flash shader doesn't sample texture).
2014-05-30 23:13:58 +02:00
Jonas Kulla 1ef6e04520 Font: Overhaul font asset discovery
Previously, any font names requested by RGSS would be translated
directly to filenames by lowercasing and replacing spaces with
underscores (and finally doing some extension substitution).
To make this whole thing work smoother as well as get closer to
how font discovery is done in VX, we now scan the "Fonts/" folder
at startup and index all present font assets by their family name;
now, if an "Open Sans" font is present in "Fonts/", it will be
used regardless of filename.

Font assets with "Regular" style are preferred, but in their
absence, mkxp will make use of any other style it can find for
the respective family. This is not the exact same behavior as
VX, but it should cover 95% of use cases.

Previously, one could substitute fonts via filenames, ie. to
substitute "Arial" with "Open Sans", one would just rename
"OpenSans.ttf" to "arial.ttf" and put it in "Fonts/". With the
above change, this is no longer possible. As an alternative, one
can now explicitly specify font family substitutions via mkxp.conf;
eg. for the above case, one would add

fontSub=Arial>Open Sans

to the configuration file. Multiple such rules can be specified.

In the process, I also added the ability to provide
'Font.(default_)name' with an array of font families to search
for the first existing one instead of a plain string.
This makes the behavior closer to RMXP; however, it doesn't
work 100% the same: when a reference to the 'Font.name' array is
held and additional strings are added to it without re-assignig
the array to 'Font.name', those will be ignored.
2014-04-16 13:37:22 +02:00
Jonas Kulla e0a4dfe372 Bitmap: Make #get_pixel/#set_pixel more accurate
This gets rid of the "batch/flush" semantics for #set_pixel
and instead just directly uploads the pixel color to the
texture, circumventing the float conversion entirely.
Also makes a lot of code simpler in many places as calling
'flush()' is no longer required for bitmaps.
2014-01-31 10:19:16 +01:00
Jonas Kulla b0a41a23e0 Rename typedef and fix wrong documenting comment 2014-01-16 19:16:09 +01:00
Jonas Kulla 1bacceddf0 Spacing 2014-01-01 12:59:40 +01:00
Jonas Kulla fbf02cf2ce Remove Qt style forloop 2013-12-27 06:19:30 +01:00
Jonas Kulla f3def32461 Constify 2013-12-27 06:11:18 +01:00
Jonas Kulla 231e38ae8e Replace QVector, QList with std::vector, std::list
An exception is made of TexPool, which will need a
bit more testing before transitioning to std containers.

Also replace 'int' with 'size_t' where it is used only
as an array index.
2013-12-26 20:18:33 +01:00
Jonas Kulla 0035c23641 Shader: Group all shaders in one collective struct
Makes sharedstate.{cpp|h} a lot easier to read, and
adding new shaders a one liner.
2013-12-11 05:22:13 +01:00
Jonas Kulla 8c6648f47e Use std algorithm functions 2013-12-08 13:19:22 +01:00
Jonas Kulla ef2430e0c3 Sanitize #include statements
The general rule I'm aiming for is to <> include
system wide / installed paths / generally everything
that's outside the git managed source tree (this means
mruby paths too!), and "" include everything else,
ie. local mkxp headers.

The only current exception are the mri headers, which
all have './' at their front as to not clash with
system wide ruby headers. I'm leaving them be for now
until I can come up with a better general solution.
2013-12-04 17:48:37 +01:00
Jonas Kulla 765fd55bce Tilemap: Use simple "TexPool" replacement for atlas allocation
Releasing a Tilemap atlas into the pool on every map switch
will blow out tons of smaller textures for very little gain,
as atlas textures are already pretty much impossible to
recycle anywhere but in new Tilemaps.
2013-10-22 06:36:13 +02:00
Jonas Kulla 397856089d Tilemap: Optimize atlas assembly from mega surface tileset
Use 'glPixelStorei()' parameters to upload sub images
directly from the same surface instead of creating
helper surfaces to upload from.
2013-10-16 19:20:36 +02:00
Jonas Kulla 39436ad231 Fix up SDL2 include paths
Using "SDL2/SDL_xxx.h" instead of "SDL_xxx.h" caused
the include paths provided by pkg-config to be ignored,
and headers from a standard include path to be used instead.
2013-10-13 23:21:34 +02:00
Jonas Kulla 23e712a730 Tilemap: Draw consecutive scanrows in one draw call
If consecutive scanrows in the scene list have no foreign
elements in between them, we batch them up and draw them
in one glDrawElements() call.

This should reduce the Tilemap induced draw calls on
average by at least 50 percent.
2013-10-13 22:00:38 +02:00
Jonas Kulla 99cfe9aefd Tilemap: Optimize scanrow z ordering 2013-10-13 12:58:56 +02:00
Jonas Kulla 4af4f5bd6b Ensure attached autotiles aren't mega surfaces 2013-10-09 18:08:44 +02:00
Jonas Kulla cb6f73f7df Rename 'GlobalState' to 'SharedState' to avoid confusion with GLState
This was particularly nasty with the shorthand macros
'gState' and 'glState'. The former is now 'shState'.
2013-10-09 12:30:33 +02:00
Jonas Kulla ba304feb54 Minor code move
Move animation based state data together and add comments
2013-10-09 11:52:39 +02:00
Jonas Kulla dd25323cdd Ifdef out more RGSS2 functionality 2013-10-06 10:28:03 +02:00
Jonas Kulla 20ec560145 Wrap color clear in 'FBO::clear()' convenience function 2013-10-01 13:10:14 +02:00
Jonas Kulla 9d34fc966b Tilemap: Clamp sampled tileset height to multiple of 32 2013-09-30 01:38:46 +02:00
Jonas Kulla 12c92d6dd0 Fix Tilemap's scanrow z sorting for good
Also make it a tad faster.
2013-09-27 04:42:22 +02:00
Jonas Kulla 0fc6022dd0 Use BlitSurface instead of UpperBlit (for forward-compat) 2013-09-25 17:07:26 +02:00
Jonas Kulla 4f08382c69 Replace 'tiles.bufferCount' with function 2013-09-24 20:11:55 +02:00
Jonas Kulla 10ec55e39b Implement a new tileset atlas layout to allow for bigger tilesets
The atlas packing algorithm has been reworked to pack autotiles
and tileset very efficiently into a texture, splitting the tileset
in multiple ways and eliminating the previous duplication of image
data in the atlas across "frames". Animation, which these frames
were designed for, is now done via duplicated buffer frames,
ie. each animation frame has its own VBO and IBO data. This was
not done to save on VRAM (hardly less memory is used), but to
make place for the new atlas layout.
Thanks to this new layout, even with a max texture size of 2048,
one can use tilesets with up to 15000 height. Of course, such
a tileset couldn't be stored in a regular Bitmap to begin with,
which is why I also introduced a hack called "mega surfaces":
software surfaces stored in RAM and wrapped inside a Bitmap,
whose sole purpose is to be passed to a Tilemap as tilesets.

Various other minor changes and fixes are included.
2013-09-24 19:35:38 +02:00
Jonas Kulla 7a6c05bba0 Implement animated flash tiles in Tilemap
Flash tiles start with an alpha of 60, which ramps up to 120
in 16 frames and 4 steps, then ramps down again over the same period.
2013-09-23 08:27:28 +02:00