72 Commits

Author SHA1 Message Date
71250104ea Better 3d falling
-Sand now can fall from and to the direction of gravity
-Registers every FallingBlock block to a different value. It doesnt
quite work though
-Removed unused code
2021-09-10 16:20:09 -04:00
51752f95f9 Merge pull request #15 from opfromthestart/falling-block
Falling block
2021-08-23 13:35:58 -04:00
175f092673 Fixed some stuff
-Added default gravity block check in server
-Some things I had to copy since i didnt merge right
-Adds all gravity blocks to FallingBlock list
-LogTop debug thing to check for good textures
-Some texture rendering(see above)
-Some control changes since I need to get to the edge quickly
2021-08-23 13:33:18 -04:00
59129f95c9 Why
-Idk this has to be "Sand" and not "Test:Sand"
2021-08-22 14:04:42 -04:00
efff41a6db Merge branch 'master' into falling-block 2021-08-22 14:03:31 -04:00
30879a1241 Merge pull request #1 from OLEGSHA/master
Uhhh pull
2021-08-22 13:47:54 -04:00
9fc1a21191 Added rock DB and worldgen
- Added Rocks container
- Added DiscreteNoise and a DIY Worley generator
- Added RockLayer
  - Used to generate rock strata
- Reworked SurfaceTerrainGenerator to use contexts
2021-08-21 23:05:54 +03:00
4f620b7261 Added 6 more types of rocks
- Added black granite, dolomite, eclogite, gabbro, limestone and marble
  - Monolith, cracked, gravel and sand variants
- Renamed Test:Granite to Test:RedGranite
- Added red granite sand
2021-08-21 17:44:01 +03:00
6f90bf345b Incremented version and made some small changes
- Version is now pre-alpha 2. Yay?
- Removed compass display in the lower-left
- The cross can now be hidden by pressing F1
  - Does not hide LayerAbout though
- Generator spawns the player in the middle of a surface rather than at
its edge
2021-08-20 21:37:49 +03:00
2328f2ae3a Replaced placeholder worldgen with a passable one
- Removed old (pre-planet) worldgen
  - TestGravityModel remains
- Moved surface generator to .logic.world.generation.surface
- Split planet generator into generator logic and config
  - Logic moved to .logic.world.generation.planet
  - Config extracted into TestGenerationConfig & others in .test.gen
  - GravityModel renamed to Test:PlanetGravityModel
- TestTerrainGenerator utilities moved and made public thru Fields
- Reconfigured planet generator to be a passable
  - Increased planet size to R=0.5 km
  - Added noise-based heightmaps (fabulous cliffs included)
  - Added noise-based forest density map
  - Reworked all SurfaceFeatures
    - TestGrassFeature now also places scatter and flowers
    - TestTreeFeature and TestBushFeature:
      - Common code exctracted to MultiblockVegetationFeature
      - Made prettier
  - gud muscle flex yeeeeeeeeeeee
- Fixed a bug in the gravity model
- A lot of other changes that I already forgot about
2021-08-20 18:07:41 +03:00
15b5d367b4 Chunk loading region around the player is now compressed vertically 2021-08-18 10:58:18 +03:00
ca2014802a Resolved a random deadlock that became way too frequent to ignore
There was a deadlock that sometimes occurred when passing PacketSetBlock
to client: PacketSetBlock first acquired monitor of the chunk it
modified, than attempted to lock the visible chunks set. In parallel, a
chunk update first acquires the visible chunks, than the individual
chunk. Turns out, markForUpdate() doesn't need to be synchronized, so
PacketSetBlock can now acquire the locks sequentially, avoiding the
deadlock.
2021-08-18 09:30:29 +03:00
539a61e854 Almost resolved feature generation issue, removed dead code
- SurfaceFeatures that change neighboring chunks no longer suffer from
tearing if world saving is enabled
  - World saving is still disabled by default
    - wontfix until we get a new, more optimized world IO system
  - See GitHub issue #13 for details
- Removed WorldAccessor getter from Server. This is an implementation
detail.
- Removed SurfaceWorld, SurfaceFeature.Request (see previous commit)
2021-08-18 00:26:45 +03:00
a3760d7425 Removed erroneous RelFace resolution by WorldAccessor 2021-08-17 19:21:57 +03:00
d33b48578d Added SurfaceContexts to replace SurfaceWorld+Request. WIP
There is a problem with features when up != POS_Z
2021-08-17 16:05:44 +03:00
a6fd81ba1e Contexts now only accept RelFace; fixed tile placement crash 2021-08-16 13:05:57 +03:00
82872c7cf3 Fixed RotatingServerContext
- RotatingServerContext now rotates coordinates, too
- Fixed a bug caused by the implementation of push methods by
TransformingServerContext
- Fixed unbounded recursion in WorldGenericRO.hasTile(Vec3i, BlockFace,
int)
2021-08-15 23:54:25 +03:00
54c66d28d6 Added TransformingServerContext and RotatingServerContext. WIP
There is a problem with faces in contexts when up != POS_Z, world
crashes soon after startup

- Added TransformingServerContext - a common basis for context wrappers
that alter the coordinate space
- Added RotatingServerContext - a context wrapper that rotates the
coordinate space
  - Used to ensure positive Z is up
- PacketAffectTile now checks the provided tile tag for validity
  - This causes a crash when the invalid action is requested, not
executed
- TickChunk task reuses contexts
2021-08-13 16:11:46 +03:00
78a1c25554 Grass tiles have regained the ability to disappear under blocks
- Test:Grass now (again) randomly disappears under opaque blocks
- Fixed a truly egregious bug in AbstractContextRO.pop()
- Fixed BlockContext.pushRelative(AbsRelation)
- Some changes in toString methods in contexts
2021-08-11 13:45:47 +03:00
a03c783fc9 Fixing bugs introduced in previous commit
- Fixed AbstractContextRO.isSubcontexting()
- Fixed push(...) overrides in FilterServerContext
- Fixed DefaultChunkLogic.tmp_generateTickLists()
- Debug screen now also lists visible and loaded chunks
- AbstractContextRO.Frame now has a toString()
2021-08-11 13:02:18 +03:00
0a45613e45 Began work on integrating the new Contexts. Compiles but does not work
- All TickContexts including TickContextMutable are deleted
- Previous occurrences of TickContexts are replaced by appropriate
ServerContexts
- Added Context.popAndReturn methods for convenience

Current known problems:
- World does not generate properly on startup
- No bulk methods in the new API (the likes of forEachTile, etc.)
- AbsFace/RelFace ambiguity in the new API (see
TestTileLogicGrass.java:68)
- TestTileLogicGrass.java:53 is disabled for some reason
2021-08-09 20:32:15 +03:00
5fb4c601ff Added ReportingServerContext
- Added ReportingServerContext to listen for write events in contexts
- Fixed method WorldGenericContextWO.setBlock(Vec3i, B)
2021-08-08 14:07:07 +03:00
020802a89c Added FilterServerContext and DefaultServerContextLogic
- Added DefaultServerContextLogic
  - A standard implementation of ServerTileContext.Logic that delegates
all methods to a ServerTileContext instance
  - Now used by DefaultServerContextImpl
- Added FilterServerContext
  - A base for creating context wrappers
2021-08-08 12:19:31 +03:00
0f909039fe Renamed ReusableServerContext to DefaultServerContext 2021-08-06 11:02:43 +03:00
15f741bc04 Added subcontexting. Context#subcontexting. 2021-08-06 10:49:40 +03:00
80541eafc3 Renamed BlockFace contexts into TileStack contexts 2021-08-05 19:39:39 +03:00
0f60d45ffa Contexts no longer expose to World, Chunks, TileStacks or TileReferences
The intention is to bottleneck all read queries and write requests
through context objects without the need to create practically useless
Chunk, TileStack and TileRef wrappers.

- WorldGenericContext{RO,WO} no longer extend WorldGeneric{RO,WO}
- Added tag access for tiles to contexts
- Documented almost all context methods
- Renamed isBlockLoaded() to isLocationLoaded()
- I found some inner peace
2021-08-05 16:42:21 +03:00
fbc803d6e2 Laid some groundwork for context implementation; rewrite incoming
- ReusableServerContext will be the default context implementation. It
is sort of implemented, but not really
- WorldLogic{,RO} now declare getData() method
- WorldGenericContextWO.removeEntity(EntityGeneric) received a default
implementation
- TileDataContext.getTag() received a default implementation
2021-08-04 18:42:16 +03:00
dccfcc9419 Better /Stuff
-Uses Coordinates a little in TestWorldGenerator. Ill do more eventually I think
-Better sprite getting for FallingBlocks
2021-08-03 15:05:05 -04:00
c2a2cc074a Some Stuff to Fix Bugs
-Improved debug info of Fallingblock ticking
-Fixed unsynchronized access as per OLEGSHA
-Maybe better server side deletion of blocks
2021-08-03 14:45:36 -04:00
1ee9a55d19 Defined Data and Server context interfaces
Server read-write (not RO) interfaces do not extend the complimentary
*GenericContextWO interfaces by design. It makes no sense to set a
BlockLogic, but it makes plenty of sense to refer to a ChunkData rather
than a ChunkDataRO.
2021-07-31 20:47:23 +03:00
a338a00f1d A change to the class hierarchy of WorldLogic similar to prev commit
- Renamed ChunkLogic -> DefaultChunkLogic, WorldLogic ->
DefaultWorldLogic
- Created/rewritten TileLogicReference{,RO}, TileLogicStack{,RO},
ChunkLogic{,RO}
- Drafted up something for ServerWorldContext & friends, WIP

(see commit 9a32660 for more details)
2021-07-31 16:01:25 +03:00
9a326603cd Still working on Contexts. Introduced a billion interfaces. WIP.
*takes a deep breath
- Renamed Generic world structure interfaces to the following scheme:

      {Block,Tile,Chunk,World}Generic{,Stack,Reference}{RO,WO}
      (e.g. GenericWritableChunk -> ChunkGenericWO)

    - RO is Read Only, WO is Write Only
- Generic writable interfaces no longer extend their read-only
counterparts (thus Write Only)
- TileGenericStack{RO,WO} are now interfaces; AbstractList is only
introduced by final implementations
- TileGenericReferenceRO now has a WO counterpart
- Fixed compilation issues with the previous commit
- Declared some additional functionality for Generic interfaces
- Old ChunkData and WorldData renamed to DefaultChunkData and
DefaultWorldData
  - Now considered to be an implementation detail; references will be
minimized
- Introduced TileDataStack{,RO}, TileDataReference{,RO}, ChunkData{,RO},
WorldData{,RO} interfaces
  - Suffix -RO indicates Read Only, no suffix means read-write
  - To be used in place of DefaultChunk and DefaultWorld
  - Designed to support wrappers and "fake" implementations
  - May need some refinement (fix return/parameter types, ...)
- Surface world generator is now implemented poorly (WIP)
- Should compile. May work fine. Unless Java inheritance rules have
screwed me over.
2021-07-23 22:46:49 +03:00
d7afe39f00 Added more generic Contexts. WIP. 2021-07-15 22:26:20 +03:00
0264e512ab Merge branch 'master' into addPlanet
Conflicts:
	src/main/java/ru/windcorp/progressia/test/LayerTestGUI.java
	src/main/java/ru/windcorp/progressia/test/TestPlayerControls.java
2021-07-12 16:20:15 +03:00
e47fb3c4bd Added surface features. Tree generation is currently broken!
- Added SurfaceFeature
  - Used to generate chunk features
- Added SurfaceTopLayerFeature
  - A superclass for features that are only concerned with editing the
surface
- Added grass, temporary bushes and temporary trees
  - Bushes and trees do not generate properly due to bugs
  - Added Test:TemporaryLeaves
- Added SurfaceWorld (a GenericWritableWorld wrapper)
- Added some unit tests for rotation utilities
- Fixed a whole lot of bugs
2021-07-07 17:37:08 +03:00
eace6733ce Added Menus and cursor visibility management
- Layers now have a CursorPolicy
  - Used to enable/disable cursor based on top layer
- Added a default menu layer implementation
2021-06-28 17:45:49 +03:00
085f602427 Panel now has decorations; functionality moved to new superclass Group 2021-06-25 17:33:46 +03:00
737b495fc4 Ported GUI improvements from opfromthestart/Progressia
These changes were originally implemented by opfromthestart. OLEGSHA
then patched a whole bunch of stuff

- Components can now be disabled
- Added BasicButton
- Added Button, Checkbox and RadioButton (with RadioButtonGroup)
- Added some new colors to Colors
- Pressing Esc in game pops up a menu (WIP)
- Fixed text z-ordering
- Fixed LayoutGrid Y-direction
2021-06-25 14:35:36 +03:00
e58007ea11 Format
Format
2021-06-10 17:09:24 -04:00
ae2980c9de Bug Fixing and Performance
-Multiple null checks(It doesn't work without them)
-Checks to make sure entities are within loaded chunks
-Actual entity removal
2021-06-10 17:00:09 -04:00
3879e5ffac Sand Towers Fall
-The listener in TestWorldGenerator updates any block above it if that block is a block that can be affected by gravity.
-Format happened(I forgot)
2021-06-10 15:56:15 -04:00
47eb9fa5af Conservation of Matter
-Placing a Test:Sand block now deletes the block and summons a Test:FallingBlock in its place.
2021-06-10 14:08:35 -04:00
bf49687ab6 Better performance maybe?
-Changed as many of the ClientState statements to context as I could.
-Only looks for a sand based update once per block update(I think it was twice before)
2021-06-10 12:50:51 -04:00
b3ae829383 Almost All Works
-Added Set in TestEntityLogicFallingBlock to keep track of gravity blocks
  -Used this set in listener in TestWorldGenerator
-setInvisible and isDone() methods in TestEntityDataFallingBlock
  -Used to determine if the entity should be rendered/cared about in TestEntityRenderFallingBlock and TestEntityLogicFallingBlock
-Added more accurate Vec3i mod and div methods in TestEntityLogicFallingBlock
  *Change this to a better place
-TestEntityLogicFallingBlock actually places the block when the entity lands
-Better air block detection in TestWorldGenerator
*Still cannot erase the original placed block, not sure why.
2021-05-09 15:57:38 -04:00
b374e9a736 Added FallingBlock Classes
-Added TestEntityDataFallingBlock class
  -Right now only supports Test:Sand
  -Kinda just copied from Statie
-Added TestEntityRenderFallingBlock
  -Used BlockRenderTexturedCube and TestEntityRenderStatie for this one
  -Has a setTexture method, but it needs improving
-Added TestEntityLogicFallingBlock class
  -Allows for a falling block to return to being a block.
  -The coordinates of the entity never move, even if it does ingame.
-In TestContent
  -Registers Test:FallingBlock
-In TestWorldGenerator
  -Adds listener for a sand block being placed
    -Listener replaces the block with a FallingBlock entity
    -It should also replace the block with air but it hasn't been working for me.
2021-05-04 20:29:06 -04:00
531a8c99c3 Added CONTRIBUTING.md. Discussion is welcome. 2021-04-27 23:22:48 +03:00
6fb7e7fc04 Added SurfaceWorld to facilitate surface feature generation 2021-04-13 15:18:15 +03:00
20dccf3d12 Some more refactoring of generic world-related classes. May not compile.
- Added GenericWritableWorld
- Moved static methods from GenericChunk to GenericChunks
- GenericEntity now declares getEntityId()
- GenericWorld now declares getEntity(long)
- Added a lambda-based mapToFaces variations for AbsFace and RelFace
2021-04-09 23:16:08 +03:00
a95bdf1efe Moved .setBlockRel(...) implementation to GenericWritableChunk 2021-04-09 20:15:07 +03:00
e0a03cad1d More refactoring of GenericChunk and pals
- Genericized TileReference
- Unified template arguments
2021-04-06 00:36:38 +03:00
2532e80f6a Moved some methods from ChunkData to GenericChunk
- Moved some method definitions from ChunkData to GenericChunk
- Moved some method definitions from ChunkData to GenericWritableChunk
- Refactored GenericChunk including changing some method signatures
- Added some documentation for GenericChunk
2021-04-05 17:30:37 +03:00
3c3f3816df Fixed a generation issue and refactored some code around WorldGenerators
- ChunkRequestDaemon now attempts to generate requested loaded non-ready
chunks upon discovery
- The server is now only specified once for WorldGenerator
- WorldLogic now actively checks the generation contract
2021-04-02 21:51:52 +03:00
2d3d250f92 Renamed Scatter to Feature and added a generation feature interface
- Renamed SurfaceScatterGenerator to SurfaceFeatureGenerator
- Renamed PlanetScatterGenerator to PlanetFeatureGenerator
- Added a very basic interface for adding generation features
- Removed debug leftovers from PlayerManager and VisionManager
2021-04-02 21:29:09 +03:00
7ecdfdfb4d Added scatter generation logic to TestPlanetGenerator
- Scatter generation is now triggered properly in TestPlanetGenerator
- WorldGenerators are now required to call addChunk() themselves (again)
- ChunkManager now generates loaded chunks that are not ready
- Chunks scheduled for unloading no longer unload if they become
requested while in queue
2021-03-26 21:26:05 +03:00
4332a78221 Refactored ChunkManager and EntityManager, added server event bus 2021-03-26 20:26:12 +03:00
ef572c43c7 Updated documentation for GuavaEventBusHijacker and ReportingEventBus 2021-03-25 17:15:03 +03:00
f28c765e3f Made Gravity Models configurable with packets 2021-03-15 21:02:33 +03:00
f4311fb27c Created a bare-bones implementation of the final planet generator
- Added Planet generator
  - Uses temporary generation algorithms
- Added Surface generator
- Added FloatRangeMap
2021-03-15 18:54:53 +03:00
abd8d9eebb Moved some functionality into WorldGenerator
- WorldGenerators now suggest a spawn location
- WorldGenerators are no longer responsible for adding chunks
2021-02-28 23:31:57 +03:00
a9a21ce664 Moved planet generation code to its own package 2021-02-28 23:03:23 +03:00
bd5a1fa04e Added rotating AABBs through lots of pain and suffering
- Collision models now rotate to match entity's general up direction
- Extracted rotation logic from RelRelation into AxisRotations
- Test:PlanetGravityModel is now properly centered
- Fixed some small bugs
2021-02-28 22:55:51 +03:00
2d55d4db51 Added a cubic gravity model and fixed some stuff
- Added TestPlanetGenerator and a corresponding gravity model
- Fixed gravity-triggered camera rotation
2021-02-22 15:38:14 +03:00
d438d2aa14 Linked GravityModel to a WorldGenerator and added GM comms transfer
- WorldData no longer acquires a GravityModel automatically
- On the server, GravityModel is specified by WorldGenerator
- On the client, GravityModel is received from the server via a
PacketSetGravityModel
2021-02-07 01:01:37 +03:00
d3c5011063 Replaced AbsFace with RelFace or BlockFace where appropriate
- Added BlockFace - a *Face superclass
- Refactored and optimized Rel{Relation, Face}
- Replaced most AbsFace references with BlockFace or RelFace
- Chunks now have an up direction
  - Determined by GravityModel's discrete up
  - Static; cannot change unless chunk is reloaded
  - Chunk models are now rendered rotated accordingly
- Fixed some minor bugs that were somehow revealed by these changes
- Moved TileLogicGrass to .test, where it belongs
- Disabled grass despawn until a new worldgen is implemented
2021-02-07 00:45:43 +03:00
10d271059c Added RelRelation and RelFace; added discrete up vector to GravityModel 2021-02-02 18:49:55 +03:00
acef9d32df Changed packages for relations, renamed Face to ShapePart
- Added BlockRelation as an abstract superclass to existing relations
  - Must be given an absolute "up" direction before use
- Moved AbsFace, AbsRelation and BlockRelation to .world.rels
- Renamed Face to ShapePart to reduce confusion with AbsFace
2021-02-01 19:14:49 +03:00
848178b343 Renamed BlockFace and BlockRelation to AbsFace and AbsRelation
- Renamed BlockFace to AbsFace
- Renamed BlockRelation to AbsRelation
- Renamed AbsFace constants using the following scheme:
  POS_X, NEG_Y, etc.
2021-02-01 17:25:07 +03:00
b1666fa4b9 Fixed a bunch of issues with gravity and implemented gravity changes
Also added DebugGraphics and made VectorUtil comply with the general Vec
contract
2021-01-31 23:34:24 +03:00
f9717be412 Switched to using looking-at vectors instead of Euler angles
Also fixed camera jittering and added some vector functions
2021-01-29 23:19:22 +03:00
553837f207 GravityModels now take position into account
- Also documented GravityModel
2021-01-25 22:06:34 +03:00
8c5493f78e Added GravityModels, removed gravity switch
- Added GravityModel
  - can specify gravity varying by location and time
  - Added GravityModelRegistry
  - Stored in WorldData
- Removed Minecraft gravity mode
2021-01-25 21:35:46 +03:00
598 changed files with 19163 additions and 8244 deletions

69
docs/CONTRIBUTING.md Normal file
View File

@ -0,0 +1,69 @@
# Contributing Guidelines
This document lists conventions adopted by Progressia developers.
## git
### Branches
Progressia repository contains a `master` branch and several "feature" branches.
`master` is expected to contain a version of the game suitable for demonstration and forking/branching. Do not commit directly to `master` without OLEGSHA's approval.
- `master` must always correctly build without compiler warnings (see below).
- `master` must always pass all unit tests.
- `master` must always be able to launch successfully.
- `master` must always only contain working features.
- `master` should not contain excessive debug code.
- `master` must always have its code and filenames formatted (see below).
"Feature" branches are branches dedicated to the development of a single feature. When the feature reaches completion the branch is merged into `master` and removed. Intermediate merges into `master` may occur when some fitting milestone is reached. Intermediate merges from `master` may be done as necessary. Merges between "feature" branches should generally be avoided.
When beginning work on a new feature, create a new branch based on `master` (or on another "feature" branch if absolutely necessary). Use `all-small-with-dashes` to name the branch: `add-trees` or `rebalance-plastics` are good names. Do not fix unrelated bugs or work on unrelated features in a "feature" branch - create a new one, switch to an existing one or commit directly to `master` if the changes are small enough.
"Feature" branches may not be formatted properly. Formatting is required before merging into `master` or other branches.
### Commits
- Commits must leave the branch in a state that builds without compiler warnings (see below).
- Changes should be grouped in commits semantically. Avoid committing many small related changes in sequence; if necessary, wait and accumulate them. Avoid committing unrelated changes together; if necessary, split staged changes into several commits. This should normally result in about 1-2 commits for a day's work.
- Commit bulk changes (renaming, formatting, ...) separately. Don't ever commit whitespace changes outside formatting commits.
- Message format:
```
Short description of changes
<empty line>
- Enumeration of changes
- Nest when appropriate
- Use dashes only
- List not needed for small commits
```
Example:
```
Changed packages for relations, renamed Face to ShapePart
- Added BlockRelation as an abstract superclass to existing relations
- Must be given an absolute "up" direction before use
- Moved AbsFace, AbsRelation and BlockRelation to .world.rels
- Renamed Face to ShapePart to reduce confusion with AbsFace
```
- Only commit changes described in the commit message. Please double-check staged files before committing.
- Avoid merge conflicts. Pull before committing.
- Better sign commits than not. See: [git](https://git-scm.com/book/en/v2/Git-Tools-Signing-Your-Work), [GitHub](https://docs.github.com/en/github/authenticating-to-github/managing-commit-signature-verification).
## Code
### Warnings
Make sure that all committed code contains no compiler warnings. This specifically includes unused imports, unused private members, missing `@Override`s and warnings related to generics.
Warnings about unknown tokens in `@SuppressWarnings` are temporarily ignored. Please disable them in your IDE.
### Code Style
Formatting code is important.
- The format is specified within the files inside `/templates_and_presets/eclipse_ide`. Import the specifications into Eclipse or IntelliJ IDEA and use the IDEs' format feature. Alternatively format the code manually in accordance with existing files.
- Only use tabs for indentation. Never indent with spaces even when wrapping lines. This is to ensure that indentation does not break when tab width is different.
- Don't use `I` prefix for interfaces (not `IDoable` but `Doable`).
- Prioritize readability over compactness. Do not hesitate to use (very) long identifiers if they aid comprehension.
- Document all mathematics unless it is trivial, especially when using math notation for variable names.
- Use proper English when writing comments. Avoid boxes in comments. Use `//` for single-line comments.

File diff suppressed because it is too large Load Diff

View File

@ -15,7 +15,7 @@
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>. * along with this program. If not, see <https://www.gnu.org/licenses/>.
*/ */
package ru.windcorp.jputil; package ru.windcorp.jputil;
import java.lang.reflect.Array; import java.lang.reflect.Array;
@ -611,8 +611,7 @@ public class ArrayUtil {
int end = offset + length; int end = offset + length;
if (end > arrayLength || offset < 0) if (end > arrayLength || offset < 0)
throw new IllegalArgumentException( throw new IllegalArgumentException(
"Array contains [0; " + arrayLength + "), requested [" + offset + "; " + end + ")" "Array contains [0; " + arrayLength + "), requested [" + offset + "; " + end + ")");
);
return length; return length;
} }
@ -628,8 +627,7 @@ public class ArrayUtil {
if (end > arrayLength || start < 0) if (end > arrayLength || start < 0)
throw new IllegalArgumentException( throw new IllegalArgumentException(
"Array contains [0; " + arrayLength + "), requested [" + start + "; " + end + ")" "Array contains [0; " + arrayLength + "), requested [" + start + "; " + end + ")");
);
return end; return end;
} }

View File

@ -15,7 +15,7 @@
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>. * along with this program. If not, see <https://www.gnu.org/licenses/>.
*/ */
package ru.windcorp.jputil; package ru.windcorp.jputil;
import java.io.OutputStream; import java.io.OutputStream;

View File

@ -15,7 +15,7 @@
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>. * along with this program. If not, see <https://www.gnu.org/licenses/>.
*/ */
package ru.windcorp.jputil; package ru.windcorp.jputil;
import java.util.HashMap; import java.util.HashMap;
@ -30,18 +30,8 @@ public class PrimitiveUtil {
private static final Map<Class<?>, Object> PRIMITIVE_TO_NULL = new HashMap<>(); private static final Map<Class<?>, Object> PRIMITIVE_TO_NULL = new HashMap<>();
static { static {
for ( for (Class<?> boxed : new Class<?>[] { Boolean.class, Byte.class, Short.class, Character.class, Integer.class,
Class<?> boxed : new Class<?>[] { Long.class, Float.class, Double.class }) {
Boolean.class,
Byte.class,
Short.class,
Character.class,
Integer.class,
Long.class,
Float.class,
Double.class
}
) {
try { try {
PRIMITIVE_TO_BOXED.put((Class<?>) boxed.getField("TYPE").get(null), boxed); PRIMITIVE_TO_BOXED.put((Class<?>) boxed.getField("TYPE").get(null), boxed);
} catch (Exception e) { } catch (Exception e) {

View File

@ -15,7 +15,7 @@
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>. * along with this program. If not, see <https://www.gnu.org/licenses/>.
*/ */
package ru.windcorp.jputil; package ru.windcorp.jputil;
import java.util.function.*; import java.util.function.*;
@ -40,8 +40,7 @@ import java.util.stream.Stream;
/** /**
* Contains static methods to create {@link Stream Streams} that synchronize * Contains static methods to create {@link Stream Streams} that synchronize
* their * their <a href=
* <a href=
* "https://docs.oracle.com/javase/8/docs/api/java/util/stream/package-summary.html#StreamOps"> * "https://docs.oracle.com/javase/8/docs/api/java/util/stream/package-summary.html#StreamOps">
* terminal operations</a> on a given monitor. * terminal operations</a> on a given monitor.
* *
@ -50,7 +49,7 @@ import java.util.stream.Stream;
*/ */
// SonarLint: "Stream.peek" should be used with caution (java:S3864) // SonarLint: "Stream.peek" should be used with caution (java:S3864)
// We are implementing Stream, so peek() is required. // We are implementing Stream, so peek() is required.
@SuppressWarnings("squid:S3864") @SuppressWarnings("squid:S3864")
public class SyncStreams { public class SyncStreams {
@ -1070,21 +1069,18 @@ public class SyncStreams {
} }
/** /**
* Wraps the given {@link Stream} to make all * Wraps the given {@link Stream} to make all <a href=
* <a href=
* "https://docs.oracle.com/javase/8/docs/api/java/util/stream/package-summary.html#StreamOps"> * "https://docs.oracle.com/javase/8/docs/api/java/util/stream/package-summary.html#StreamOps">
* terminal operations</a> acquire the provided monitor's lock before * terminal operations</a> acquire the provided monitor's lock before
* execution. Intermediate operations * execution. Intermediate operations return streams that are also
* return streams that are also synchronized on the same object. The created * synchronized on the same object. The created stream will behave
* stream will behave identically * identically to the provided stream in all other aspects. Use this to
* to the provided stream in all other aspects. Use this to synchronize * synchronize access to stream's source.
* access to stream's source.
* <p> * <p>
* <i>The returned {@code Stream}'s {@link Stream#iterator() iterator()} and * <i>The returned {@code Stream}'s {@link Stream#iterator() iterator()} and
* {@link Stream#spliterator() * {@link Stream#spliterator() spliterator()} methods return regular
* spliterator()} methods return regular non-synchronized iterators and * non-synchronized iterators and spliterators respectively</i>. It is the
* spliterators respectively</i>. It * user's responsibility to avoid concurrency issues:
* is the user's responsibility to avoid concurrency issues:
* *
* <pre> * <pre>
* synchronized (stream.getMonitor()) { * synchronized (stream.getMonitor()) {
@ -1103,14 +1099,17 @@ public class SyncStreams {
* stream.forEach(System.out::println); // Should never throw a ConcurrentModificationException * stream.forEach(System.out::println); // Should never throw a ConcurrentModificationException
* </pre> * </pre>
* *
* @param <T> the class of objects in the Stream * @param <T>
* @param stream the stream to wrap. * the class of objects in the Stream
* @param monitor the object that the stream will use for synchronization. * @param stream
* When {@code null}, the stream * the stream to wrap.
* will synchronize on itself. * @param monitor
* the object that the stream will use for synchronization. When
* {@code null}, the stream will synchronize on itself.
* @return a {@link SyncStream SyncStream&lt;T&gt;} synchronized on * @return a {@link SyncStream SyncStream&lt;T&gt;} synchronized on
* {@code monitor} and backed by {@code stream}. * {@code monitor} and backed by {@code stream}.
* @throws NullPointerException if {@code stream == null}. * @throws NullPointerException
* if {@code stream == null}.
*/ */
public static <T> SyncStream<T> synchronizedStream(Stream<T> stream, Object monitor) { public static <T> SyncStream<T> synchronizedStream(Stream<T> stream, Object monitor) {
Objects.requireNonNull(stream, "stream cannot be null"); Objects.requireNonNull(stream, "stream cannot be null");
@ -1118,22 +1117,19 @@ public class SyncStreams {
} }
/** /**
* Wraps the given {@link IntStream} to make all * Wraps the given {@link IntStream} to make all <a href=
* <a href=
* "https://docs.oracle.com/javase/8/docs/api/java/util/stream/package-summary.html#StreamOps"> * "https://docs.oracle.com/javase/8/docs/api/java/util/stream/package-summary.html#StreamOps">
* terminal operations</a> acquire the provided monitor's lock before * terminal operations</a> acquire the provided monitor's lock before
* execution. Intermediate operations * execution. Intermediate operations return streams that are also
* return streams that are also synchronized on the same object. The created * synchronized on the same object. The created stream will behave
* stream will behave identically * identically to the provided stream in all other aspects. Use this to
* to the provided stream in all other aspects. Use this to synchronize * synchronize access to stream's source.
* access to stream's source.
* <p> * <p>
* <i>The returned {@code IntStream}'s {@link IntStream#iterator() * <i>The returned {@code IntStream}'s {@link IntStream#iterator()
* iterator()} and * iterator()} and {@link IntStream#spliterator() spliterator()} methods
* {@link IntStream#spliterator() spliterator()} methods return regular * return regular non-synchronized iterators and spliterators
* non-synchronized iterators and * respectively</i>. It is the user's responsibility to avoid concurrency
* spliterators respectively</i>. It is the user's responsibility to avoid * issues:
* concurrency issues:
* *
* <pre> * <pre>
* synchronized (stream.getMonitor()) { * synchronized (stream.getMonitor()) {
@ -1152,13 +1148,15 @@ public class SyncStreams {
* stream.forEach(System.out::println); // Should never throw a ConcurrentModificationException * stream.forEach(System.out::println); // Should never throw a ConcurrentModificationException
* </pre> * </pre>
* *
* @param stream the stream to wrap. * @param stream
* @param monitor the object that the stream will use for synchronization. * the stream to wrap.
* When {@code null}, the stream * @param monitor
* will synchronize on itself. * the object that the stream will use for synchronization. When
* {@code null}, the stream will synchronize on itself.
* @return a {@link SyncIntStream} synchronized on {@code monitor} and * @return a {@link SyncIntStream} synchronized on {@code monitor} and
* backed by {@code stream}. * backed by {@code stream}.
* @throws NullPointerException if {@code stream == null}. * @throws NullPointerException
* if {@code stream == null}.
*/ */
public static SyncIntStream synchronizedStream(IntStream stream, Object monitor) { public static SyncIntStream synchronizedStream(IntStream stream, Object monitor) {
Objects.requireNonNull(stream, "stream cannot be null"); Objects.requireNonNull(stream, "stream cannot be null");
@ -1166,22 +1164,19 @@ public class SyncStreams {
} }
/** /**
* Wraps the given {@link LongStream} to make all * Wraps the given {@link LongStream} to make all <a href=
* <a href=
* "https://docs.oracle.com/javase/8/docs/api/java/util/stream/package-summary.html#StreamOps"> * "https://docs.oracle.com/javase/8/docs/api/java/util/stream/package-summary.html#StreamOps">
* terminal operations</a> acquire the provided monitor's lock before * terminal operations</a> acquire the provided monitor's lock before
* execution. Intermediate operations * execution. Intermediate operations return streams that are also
* return streams that are also synchronized on the same object. The created * synchronized on the same object. The created stream will behave
* stream will behave identically * identically to the provided stream in all other aspects. Use this to
* to the provided stream in all other aspects. Use this to synchronize * synchronize access to stream's source.
* access to stream's source.
* <p> * <p>
* <i>The returned {@code LongStream}'s {@link LongStream#iterator() * <i>The returned {@code LongStream}'s {@link LongStream#iterator()
* iterator()} and * iterator()} and {@link LongStream#spliterator() spliterator()} methods
* {@link LongStream#spliterator() spliterator()} methods return regular * return regular non-synchronized iterators and spliterators
* non-synchronized iterators and * respectively</i>. It is the user's responsibility to avoid concurrency
* spliterators respectively</i>. It is the user's responsibility to avoid * issues:
* concurrency issues:
* *
* <pre> * <pre>
* synchronized (stream.getMonitor()) { * synchronized (stream.getMonitor()) {
@ -1200,13 +1195,15 @@ public class SyncStreams {
* stream.forEach(System.out::println); // Should never throw a ConcurrentModificationException * stream.forEach(System.out::println); // Should never throw a ConcurrentModificationException
* </pre> * </pre>
* *
* @param stream the stream to wrap. * @param stream
* @param monitor the object that the stream will use for synchronization. * the stream to wrap.
* When {@code null}, the stream * @param monitor
* will synchronize on itself. * the object that the stream will use for synchronization. When
* {@code null}, the stream will synchronize on itself.
* @return a {@link SyncLongStream} synchronized on {@code monitor} and * @return a {@link SyncLongStream} synchronized on {@code monitor} and
* backed by {@code stream}. * backed by {@code stream}.
* @throws NullPointerException if {@code stream == null}. * @throws NullPointerException
* if {@code stream == null}.
*/ */
public static SyncLongStream synchronizedStream(LongStream stream, Object monitor) { public static SyncLongStream synchronizedStream(LongStream stream, Object monitor) {
Objects.requireNonNull(stream, "stream cannot be null"); Objects.requireNonNull(stream, "stream cannot be null");
@ -1214,22 +1211,19 @@ public class SyncStreams {
} }
/** /**
* Wraps the given {@link DoubleStream} to make all * Wraps the given {@link DoubleStream} to make all <a href=
* <a href=
* "https://docs.oracle.com/javase/8/docs/api/java/util/stream/package-summary.html#StreamOps"> * "https://docs.oracle.com/javase/8/docs/api/java/util/stream/package-summary.html#StreamOps">
* terminal operations</a> acquire the provided monitor's lock before * terminal operations</a> acquire the provided monitor's lock before
* execution. Intermediate operations * execution. Intermediate operations return streams that are also
* return streams that are also synchronized on the same object. The created * synchronized on the same object. The created stream will behave
* stream will behave identically * identically to the provided stream in all other aspects. Use this to
* to the provided stream in all other aspects. Use this to synchronize * synchronize access to stream's source.
* access to stream's source.
* <p> * <p>
* <i>The returned {@code DoubleStream}'s {@link DoubleStream#iterator() * <i>The returned {@code DoubleStream}'s {@link DoubleStream#iterator()
* iterator()} and * iterator()} and {@link DoubleStream#spliterator() spliterator()} methods
* {@link DoubleStream#spliterator() spliterator()} methods return regular * return regular non-synchronized iterators and spliterators
* non-synchronized iterators and * respectively</i>. It is the user's responsibility to avoid concurrency
* spliterators respectively</i>. It is the user's responsibility to avoid * issues:
* concurrency issues:
* *
* <pre> * <pre>
* synchronized (stream.getMonitor()) { * synchronized (stream.getMonitor()) {
@ -1248,13 +1242,15 @@ public class SyncStreams {
* stream.forEach(System.out::println); // Should never throw a ConcurrentModificationException * stream.forEach(System.out::println); // Should never throw a ConcurrentModificationException
* </pre> * </pre>
* *
* @param stream the stream to wrap. * @param stream
* @param monitor the object that the stream will use for synchronization. * the stream to wrap.
* When {@code null}, the stream * @param monitor
* will synchronize on itself. * the object that the stream will use for synchronization. When
* {@code null}, the stream will synchronize on itself.
* @return a {@link SyncDoubleStream} synchronized on {@code monitor} and * @return a {@link SyncDoubleStream} synchronized on {@code monitor} and
* backed by {@code stream}. * backed by {@code stream}.
* @throws NullPointerException if {@code stream == null}. * @throws NullPointerException
* if {@code stream == null}.
*/ */
public static SyncDoubleStream synchronizedStream(DoubleStream stream, Object monitor) { public static SyncDoubleStream synchronizedStream(DoubleStream stream, Object monitor) {
Objects.requireNonNull(stream, "stream cannot be null"); Objects.requireNonNull(stream, "stream cannot be null");

View File

@ -15,7 +15,7 @@
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>. * along with this program. If not, see <https://www.gnu.org/licenses/>.
*/ */
package ru.windcorp.jputil; package ru.windcorp.jputil;
public class SyntaxException extends Exception { public class SyntaxException extends Exception {

View File

@ -15,7 +15,7 @@
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>. * along with this program. If not, see <https://www.gnu.org/licenses/>.
*/ */
package ru.windcorp.jputil.chars; package ru.windcorp.jputil.chars;
import java.text.CharacterIterator; import java.text.CharacterIterator;
@ -108,7 +108,7 @@ public class CharArrayIterator implements CharacterIterator {
return pos; return pos;
} }
// @SuppressWarnings("all") Just STFU, this _is_ terrific // @SuppressWarnings("all") Just STFU, this _is_ terrific
// SonarLint: "clone" should not be overridden (java:S2975) // SonarLint: "clone" should not be overridden (java:S2975)
// And I wouldn't have done that if only CharacterIterator had not required // And I wouldn't have done that if only CharacterIterator had not required

View File

@ -15,7 +15,7 @@
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>. * along with this program. If not, see <https://www.gnu.org/licenses/>.
*/ */
package ru.windcorp.jputil.chars; package ru.windcorp.jputil.chars;
import java.util.function.IntConsumer; import java.util.function.IntConsumer;

View File

@ -15,7 +15,7 @@
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>. * along with this program. If not, see <https://www.gnu.org/licenses/>.
*/ */
package ru.windcorp.jputil.chars; package ru.windcorp.jputil.chars;
import java.util.Objects; import java.util.Objects;

View File

@ -15,7 +15,7 @@
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>. * along with this program. If not, see <https://www.gnu.org/licenses/>.
*/ */
package ru.windcorp.jputil.chars; package ru.windcorp.jputil.chars;
import java.util.Arrays; import java.util.Arrays;

View File

@ -15,7 +15,7 @@
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>. * along with this program. If not, see <https://www.gnu.org/licenses/>.
*/ */
package ru.windcorp.jputil.chars; package ru.windcorp.jputil.chars;
import java.util.function.IntSupplier; import java.util.function.IntSupplier;

View File

@ -15,7 +15,7 @@
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>. * along with this program. If not, see <https://www.gnu.org/licenses/>.
*/ */
package ru.windcorp.jputil.chars; package ru.windcorp.jputil.chars;
public class EscapeException extends Exception { public class EscapeException extends Exception {

View File

@ -15,7 +15,7 @@
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>. * along with this program. If not, see <https://www.gnu.org/licenses/>.
*/ */
package ru.windcorp.jputil.chars; package ru.windcorp.jputil.chars;
import java.text.CharacterIterator; import java.text.CharacterIterator;
@ -103,14 +103,8 @@ public class Escaper {
} }
public static final Escaper JAVA = new Escaper( public static final Escaper JAVA = new Escaper('\\', 'u', "tbnrf'\"".toCharArray(), "\t\b\n\r\f\'\"".toCharArray(),
'\\', true, true);
'u',
"tbnrf'\"".toCharArray(),
"\t\b\n\r\f\'\"".toCharArray(),
true,
true
);
private final char escapeChar; private final char escapeChar;
private final char unicodeEscapeChar; private final char unicodeEscapeChar;
@ -120,14 +114,8 @@ public class Escaper {
private final boolean preferUnicode; private final boolean preferUnicode;
private final boolean strict; private final boolean strict;
protected Escaper( protected Escaper(char escapeChar, char unicodeEscapeChar, char[] safes, char[] unsafes, boolean preferUnicode,
char escapeChar, boolean strict) {
char unicodeEscapeChar,
char[] safes,
char[] unsafes,
boolean preferUnicode,
boolean strict
) {
this.escapeChar = escapeChar; this.escapeChar = escapeChar;
this.unicodeEscapeChar = unicodeEscapeChar; this.unicodeEscapeChar = unicodeEscapeChar;
this.safes = safes; this.safes = safes;
@ -152,8 +140,7 @@ public class Escaper {
for (char c : unsafes) { for (char c : unsafes) {
if (c == escapeChar) if (c == escapeChar)
throw new IllegalArgumentException( throw new IllegalArgumentException(
"Unsafe characters contain escape chatacter (escape character is escaped automatically)" "Unsafe characters contain escape chatacter (escape character is escaped automatically)");
);
if (c == unicodeEscapeChar) if (c == unicodeEscapeChar)
throw new IllegalArgumentException("Unsafe characters contain Unicode escape chatacter"); throw new IllegalArgumentException("Unsafe characters contain Unicode escape chatacter");
} }
@ -173,11 +160,7 @@ public class Escaper {
end = Integer.MAX_VALUE; end = Integer.MAX_VALUE;
else else
end = src.getPosition() + length; end = src.getPosition() + length;
while ( while (src.has() && src.getPosition() < end && (until == null || !until.test(src.current())))
src.has() &&
src.getPosition() < end &&
(until == null || !until.test(src.current()))
)
escape(src.consume(), output); escape(src.consume(), output);
} }
@ -225,11 +208,7 @@ public class Escaper {
int result = 0; int result = 0;
while ( while (src.has() && src.getPosition() < end && (until == null || !until.test(src.current()))) {
src.has() &&
src.getPosition() < end &&
(until == null || !until.test(src.current()))
) {
result += getEscapedLength(src.consume()); result += getEscapedLength(src.consume());
} }
@ -257,11 +236,7 @@ public class Escaper {
end = Integer.MAX_VALUE; end = Integer.MAX_VALUE;
else else
end = src.getPosition() + length; end = src.getPosition() + length;
while ( while (src.has() && src.getPosition() < end && (until == null || !until.test(src.current()))) {
src.has() &&
src.getPosition() < end &&
(until == null || !until.test(src.current()))
) {
output.accept(unescapeOneSequence(src)); output.accept(unescapeOneSequence(src));
} }
} }
@ -282,10 +257,8 @@ public class Escaper {
if (src.current() == unicodeEscapeChar) { if (src.current() == unicodeEscapeChar) {
src.next(); src.next();
return (char) (hexValue(src.consume()) << (4 * 3) | return (char) (hexValue(src.consume()) << (4 * 3) | hexValue(src.consume()) << (4 * 2)
hexValue(src.consume()) << (4 * 2) | | hexValue(src.consume()) << (4 * 1) | hexValue(src.consume()) << (4 * 0));
hexValue(src.consume()) << (4 * 1) |
hexValue(src.consume()) << (4 * 0));
} }
int index = ArrayUtil.firstIndexOf(safes, src.current()); int index = ArrayUtil.firstIndexOf(safes, src.current());
@ -315,11 +288,7 @@ public class Escaper {
int result = 0; int result = 0;
while ( while (src.has() && src.getPosition() < end && (until == null || !until.test(src.current()))) {
src.has() &&
src.getPosition() < end &&
(until == null || !until.test(src.current()))
) {
skipOneSequence(src); skipOneSequence(src);
result++; result++;
} }
@ -328,11 +297,7 @@ public class Escaper {
} }
public void skipOneSequence(CharReader src) { public void skipOneSequence(CharReader src) {
if ( if (src.current() == escapeChar && src.next() == unicodeEscapeChar) {
src.current() == escapeChar
&&
src.next() == unicodeEscapeChar
) {
src.advance(4); src.advance(4);
} }
src.next(); src.next();

View File

@ -15,7 +15,7 @@
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>. * along with this program. If not, see <https://www.gnu.org/licenses/>.
*/ */
package ru.windcorp.jputil.chars; package ru.windcorp.jputil.chars;
import java.text.CharacterIterator; import java.text.CharacterIterator;
@ -86,7 +86,7 @@ public class FancyCharacterIterator implements CharacterIterator {
return sb.toString(); return sb.toString();
} }
// @SuppressWarnings("all") Just STFU, this _is_ terrific // @SuppressWarnings("all") Just STFU, this _is_ terrific
// SonarLint: "clone" should not be overridden (java:S2975) // SonarLint: "clone" should not be overridden (java:S2975)
// And I wouldn't have done that if only CharacterIterator had not required // And I wouldn't have done that if only CharacterIterator had not required

View File

@ -15,7 +15,7 @@
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>. * along with this program. If not, see <https://www.gnu.org/licenses/>.
*/ */
package ru.windcorp.jputil.chars; package ru.windcorp.jputil.chars;
public class IndentedStringBuilder { public class IndentedStringBuilder {

View File

@ -15,7 +15,7 @@
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>. * along with this program. If not, see <https://www.gnu.org/licenses/>.
*/ */
package ru.windcorp.jputil.chars; package ru.windcorp.jputil.chars;
import java.io.IOException; import java.io.IOException;
@ -41,13 +41,8 @@ public class StringUtil {
private static final String EMPTY_PLACEHOLDER = "[empty]"; private static final String EMPTY_PLACEHOLDER = "[empty]";
private static final String DEFAULT_SEPARATOR = "; "; private static final String DEFAULT_SEPARATOR = "; ";
public static <T> String arrayToString( public static <T> String arrayToString(T[] array, String separator, String empty, String nullPlaceholder,
T[] array, String nullArray) {
String separator,
String empty,
String nullPlaceholder,
String nullArray
) {
if (separator == null) { if (separator == null) {
throw new IllegalArgumentException(new NullPointerException()); throw new IllegalArgumentException(new NullPointerException());
@ -79,13 +74,8 @@ public class StringUtil {
return arrayToString(array, DEFAULT_SEPARATOR); return arrayToString(array, DEFAULT_SEPARATOR);
} }
public static String iteratorToString( public static String iteratorToString(Iterator<?> iterator, String separator, String empty, String nullPlaceholder,
Iterator<?> iterator, String nullIterator) {
String separator,
String empty,
String nullPlaceholder,
String nullIterator
) {
if (separator == null) { if (separator == null) {
throw new IllegalArgumentException(new NullPointerException()); throw new IllegalArgumentException(new NullPointerException());
@ -119,13 +109,8 @@ public class StringUtil {
return iteratorToString(iterator, DEFAULT_SEPARATOR); return iteratorToString(iterator, DEFAULT_SEPARATOR);
} }
public static String iterableToString( public static String iterableToString(Iterable<?> iterable, String separator, String empty, String nullPlaceholder,
Iterable<?> iterable, String nullIterable) {
String separator,
String empty,
String nullPlaceholder,
String nullIterable
) {
if (separator == null) { if (separator == null) {
throw new IllegalArgumentException(new NullPointerException()); throw new IllegalArgumentException(new NullPointerException());
@ -146,14 +131,8 @@ public class StringUtil {
return iterableToString(iterable, DEFAULT_SEPARATOR); return iterableToString(iterable, DEFAULT_SEPARATOR);
} }
public static <T> String supplierToString( public static <T> String supplierToString(IntFunction<T> supplier, int length, String separator, String empty,
IntFunction<T> supplier, String nullPlaceholder, String nullSupplier) {
int length,
String separator,
String empty,
String nullPlaceholder,
String nullSupplier
) {
if (separator == null) if (separator == null)
throw new IllegalArgumentException(new NullPointerException()); throw new IllegalArgumentException(new NullPointerException());
@ -163,28 +142,15 @@ public class StringUtil {
return empty; return empty;
if (length > 0) { if (length > 0) {
return supplierToStringExactly( return supplierToStringExactly(supplier, length, separator, nullPlaceholder);
supplier,
length,
separator,
nullPlaceholder
);
} else { } else {
return supplierToStringUntilNull( return supplierToStringUntilNull(supplier, separator, empty);
supplier,
separator,
empty
);
} }
} }
private static <T> String supplierToStringExactly( private static <T> String supplierToStringExactly(IntFunction<T> supplier, int length, String separator,
IntFunction<T> supplier, String nullPlaceholder) {
int length,
String separator,
String nullPlaceholder
) {
T element = supplier.apply(0); T element = supplier.apply(0);
StringBuilder sb = new StringBuilder(element == null ? nullPlaceholder : element.toString()); StringBuilder sb = new StringBuilder(element == null ? nullPlaceholder : element.toString());
@ -198,11 +164,7 @@ public class StringUtil {
return sb.toString(); return sb.toString();
} }
private static <T> String supplierToStringUntilNull( private static <T> String supplierToStringUntilNull(IntFunction<T> supplier, String separator, String empty) {
IntFunction<T> supplier,
String separator,
String empty
) {
T element = supplier.apply(0); T element = supplier.apply(0);
if (element == null) { if (element == null) {
@ -366,11 +328,7 @@ public class StringUtil {
StringBuilder sb = new StringBuilder(); StringBuilder sb = new StringBuilder();
charLoop: for (char c : src.toCharArray()) { charLoop: for (char c : src.toCharArray()) {
if ( if ((resultIndex + 1) < arrayLength && test.test(c)) {
(resultIndex + 1) < arrayLength
&&
test.test(c)
) {
result[resultIndex] = resetStringBuilder(sb); result[resultIndex] = resetStringBuilder(sb);
++resultIndex; ++resultIndex;
continue charLoop; continue charLoop;
@ -389,17 +347,17 @@ public class StringUtil {
* index. * index.
* <p> * <p>
* Indices {@code 0} and {@code src.length() - 1} produce {@code str} * Indices {@code 0} and {@code src.length() - 1} produce {@code str}
* excluding * excluding the specified character and {@code ""}.
* the specified character and {@code ""}.
* <p> * <p>
* *
* @param src the String to split * @param src
* @param at index to split at * the String to split
* @throws IllegalArgumentException if the index is out of bounds for * @param at
* {@code src} * index to split at
* @throws IllegalArgumentException
* if the index is out of bounds for {@code src}
* @return an array containing the substrings, in order of encounter in * @return an array containing the substrings, in order of encounter in
* {@code src}. * {@code src}. Its length is always 2.
* Its length is always 2.
*/ */
public static String[] splitAt(String src, int at) { public static String[] splitAt(String src, int at) {
Objects.requireNonNull(src, "src"); Objects.requireNonNull(src, "src");
@ -416,10 +374,7 @@ public class StringUtil {
return new String[] { src.substring(0, src.length() - 1), "" }; return new String[] { src.substring(0, src.length() - 1), "" };
} }
return new String[] { return new String[] { src.substring(0, at), src.substring(at + 1) };
src.substring(0, at),
src.substring(at + 1)
};
} }
/** /**
@ -427,8 +382,7 @@ public class StringUtil {
* indices. * indices.
* <p> * <p>
* Indices {@code 0} and {@code src.length() - 1} produce extra zero-length * Indices {@code 0} and {@code src.length() - 1} produce extra zero-length
* outputs. * outputs. Duplicate indices produce extra zero-length outputs.
* Duplicate indices produce extra zero-length outputs.
* <p> * <p>
* Examples: * Examples:
* *
@ -439,13 +393,14 @@ public class StringUtil {
* splitAt("a.b", 1, 1, 1) -> {"a", "", "", "b"} * splitAt("a.b", 1, 1, 1) -> {"a", "", "", "b"}
* </pre> * </pre>
* *
* @param src the String to split * @param src
* @param at indices to split at, in any order * the String to split
* @throws IllegalArgumentException if some index is out of bounds for * @param at
* {@code src} * indices to split at, in any order
* @throws IllegalArgumentException
* if some index is out of bounds for {@code src}
* @return an array containing the substrings, in order of encounter in * @return an array containing the substrings, in order of encounter in
* {@code src}. * {@code src}. Its length is always {@code at.length + 1}.
* Its length is always {@code at.length + 1}.
*/ */
public static String[] splitAt(String src, int... at) { public static String[] splitAt(String src, int... at) {
Objects.requireNonNull(src, "src"); Objects.requireNonNull(src, "src");
@ -553,10 +508,8 @@ public class StringUtil {
} }
if (endPos < beginPos) { if (endPos < beginPos) {
throw new IllegalArgumentException( throw new IllegalArgumentException("endPos must be greater than or equal to beginPos (endPos=" + endPos
"endPos must be greater than or equal to beginPos (endPos=" + ", beginPos=" + beginPos + ")");
+ endPos + ", beginPos=" + beginPos + ")"
);
} }
if (endPos >= Math.min(a.length, b.length)) { if (endPos >= Math.min(a.length, b.length)) {
@ -592,8 +545,7 @@ public class StringUtil {
/** /**
* Finds and returns the index of the specified appearance of the specified * Finds and returns the index of the specified appearance of the specified
* character * character in the given array. The search starts at index 0.
* in the given array. The search starts at index 0.
* <p> * <p>
* Examples: * Examples:
* <p> * <p>
@ -630,10 +582,12 @@ public class StringUtil {
* </tr> * </tr>
* </table> * </table>
* *
* @param src - the array to search in. * @param src
* @param target - the character to search for. * - the array to search in.
* @param skip - the amount of <code>target</code> characters to be * @param target
* skipped. * - the character to search for.
* @param skip
* - the amount of <code>target</code> characters to be skipped.
* @return The index of the <code>skip+1</code>th <code>target</code> * @return The index of the <code>skip+1</code>th <code>target</code>
* character or -1, if none found. * character or -1, if none found.
* @see StringUtil#indexFromEnd(char[], char, int) * @see StringUtil#indexFromEnd(char[], char, int)
@ -653,8 +607,7 @@ public class StringUtil {
/** /**
* Finds and returns the index of the specified appearance of the specified * Finds and returns the index of the specified appearance of the specified
* character * character in the given array. The search starts at index
* in the given array. The search starts at index
* <code>src.length - 1</code>. * <code>src.length - 1</code>.
* <p> * <p>
* Examples: * Examples:
@ -692,13 +645,15 @@ public class StringUtil {
* </tr> * </tr>
* </table> * </table>
* *
* @param src - the array to search in. * @param src
* @param target - the character to search for. * - the array to search in.
* @param skip - the amount of <code>target</code> characters to be * @param target
* skipped. * - the character to search for.
* @param skip
* - the amount of <code>target</code> characters to be skipped.
* @return The index of the <code>skip+1</code>th * @return The index of the <code>skip+1</code>th
* <code>target</code>character * <code>target</code>character from the end of the array or -1, if
* from the end of the array or -1, if none found. * none found.
* @see StringUtil#indexFromBeginning(char[], char, int) * @see StringUtil#indexFromBeginning(char[], char, int)
*/ */
public static int indexFromEnd(char[] src, char target, int skip) { public static int indexFromEnd(char[] src, char target, int skip) {
@ -873,12 +828,8 @@ public class StringUtil {
return result; return result;
} }
private static void buildCombinations( private static void buildCombinations(StringBuilder sb, Collection<String> result, Iterable<String>[] parts,
StringBuilder sb, int index) {
Collection<String> result,
Iterable<String>[] parts,
int index
) {
if (index >= parts.length) { if (index >= parts.length) {
result.add(sb.toString()); result.add(sb.toString());
} else { } else {
@ -904,13 +855,8 @@ public class StringUtil {
return result; return result;
} }
private static void buildCombinations( private static void buildCombinations(StringBuilder sb, String[] result, int[] resultIndex, String[][] parts,
StringBuilder sb, int index) {
String[] result,
int[] resultIndex,
String[][] parts,
int index
) {
if (index >= parts.length) { if (index >= parts.length) {
result[resultIndex[0]++] = sb.toString(); result[resultIndex[0]++] = sb.toString();
} else { } else {
@ -985,10 +931,7 @@ public class StringUtil {
} }
private static char hexDigit(long value, int digit) { private static char hexDigit(long value, int digit) {
return hexDigit( return hexDigit((int) (value >>> (4 * digit)) & 0xF);
(int) (value >>> (4 * digit))
& 0xF
);
} }
public static char hexDigit(int value) { public static char hexDigit(int value) {

View File

@ -15,7 +15,7 @@
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>. * along with this program. If not, see <https://www.gnu.org/licenses/>.
*/ */
package ru.windcorp.jputil.chars; package ru.windcorp.jputil.chars;
public class UncheckedEscapeException extends RuntimeException { public class UncheckedEscapeException extends RuntimeException {

View File

@ -15,7 +15,7 @@
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>. * along with this program. If not, see <https://www.gnu.org/licenses/>.
*/ */
package ru.windcorp.jputil.chars; package ru.windcorp.jputil.chars;
import java.io.IOException; import java.io.IOException;

View File

@ -15,7 +15,7 @@
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>. * along with this program. If not, see <https://www.gnu.org/licenses/>.
*/ */
package ru.windcorp.jputil.chars.reader; package ru.windcorp.jputil.chars.reader;
/** /**
@ -27,10 +27,9 @@ public abstract class AbstractCharReader implements CharReader {
/** /**
* Current position of this CharReader. The reader maps its input to * Current position of this CharReader. The reader maps its input to
* positions starting from 0. * positions starting from 0. Positions that are negative or lower than 0
* Positions that are negative or lower than 0 are invalid. * are invalid. {@link #current()} will throw an exception if position is
* {@link #current()} * invalid.
* will throw an exception if position is invalid.
*/ */
protected int position = 0; protected int position = 0;

View File

@ -15,7 +15,7 @@
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>. * along with this program. If not, see <https://www.gnu.org/licenses/>.
*/ */
package ru.windcorp.jputil.chars.reader; package ru.windcorp.jputil.chars.reader;
import java.util.Objects; import java.util.Objects;

View File

@ -15,7 +15,7 @@
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>. * along with this program. If not, see <https://www.gnu.org/licenses/>.
*/ */
package ru.windcorp.jputil.chars.reader; package ru.windcorp.jputil.chars.reader;
/** /**
@ -51,9 +51,12 @@ public abstract class BufferedCharReader extends AbstractCharReader {
/** /**
* Acquires next characters and stores them in the array. * Acquires next characters and stores them in the array.
* *
* @param buffer the output array * @param buffer
* @param offset index of the first character * the output array
* @param length maximum amount of characters to be pulled * @param offset
* index of the first character
* @param length
* maximum amount of characters to be pulled
* @return the amount of characters actually pulled * @return the amount of characters actually pulled
*/ */
protected int pullChars(char[] buffer, int offset, int length) { protected int pullChars(char[] buffer, int offset, int length) {

View File

@ -15,7 +15,7 @@
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>. * along with this program. If not, see <https://www.gnu.org/licenses/>.
*/ */
package ru.windcorp.jputil.chars.reader; package ru.windcorp.jputil.chars.reader;
import java.io.IOException; import java.io.IOException;
@ -30,7 +30,7 @@ import ru.windcorp.jputil.chars.Escaper;
*/ */
// SonarLint: Constants should not be defined in interfaces (java:S1214) // SonarLint: Constants should not be defined in interfaces (java:S1214)
// DONE is an essential part of the interface // DONE is an essential part of the interface
@SuppressWarnings("squid:S1214") @SuppressWarnings("squid:S1214")
public interface CharReader { public interface CharReader {
@ -179,8 +179,7 @@ public interface CharReader {
/** /**
* Skips to the end of the current line. Both <code>"\n"</code>, * Skips to the end of the current line. Both <code>"\n"</code>,
* <code>"\r"</code> * <code>"\r"</code> and <code>"\r\n"</code> are considered line separators.
* and <code>"\r\n"</code> are considered line separators.
* *
* @return the amount of characters in the skipped line * @return the amount of characters in the skipped line
*/ */

View File

@ -15,7 +15,7 @@
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>. * along with this program. If not, see <https://www.gnu.org/licenses/>.
*/ */
package ru.windcorp.jputil.chars.reader; package ru.windcorp.jputil.chars.reader;
import java.io.InputStream; import java.io.InputStream;

View File

@ -15,7 +15,7 @@
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>. * along with this program. If not, see <https://www.gnu.org/licenses/>.
*/ */
package ru.windcorp.jputil.chars.reader; package ru.windcorp.jputil.chars.reader;
import java.io.IOException; import java.io.IOException;

View File

@ -15,7 +15,7 @@
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>. * along with this program. If not, see <https://www.gnu.org/licenses/>.
*/ */
package ru.windcorp.jputil.chars.reader; package ru.windcorp.jputil.chars.reader;
import java.util.Objects; import java.util.Objects;
@ -38,8 +38,7 @@ public class StringCharReader extends AbstractCharReader {
int end = offset + length; int end = offset + length;
if (end > str.length() || offset < 0) if (end > str.length() || offset < 0)
throw new IllegalArgumentException( throw new IllegalArgumentException(
"String contains [0; " + str.length() + "), requested [" + offset + "; " + end + ")" "String contains [0; " + str.length() + "), requested [" + offset + "; " + end + ")");
);
this.offset = offset; this.offset = offset;
this.length = length; this.length = length;

View File

@ -15,7 +15,7 @@
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>. * along with this program. If not, see <https://www.gnu.org/licenses/>.
*/ */
package ru.windcorp.jputil.functions; package ru.windcorp.jputil.functions;
@FunctionalInterface @FunctionalInterface

View File

@ -15,7 +15,7 @@
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>. * along with this program. If not, see <https://www.gnu.org/licenses/>.
*/ */
package ru.windcorp.jputil.functions; package ru.windcorp.jputil.functions;
import java.util.function.BiConsumer; import java.util.function.BiConsumer;
@ -44,9 +44,16 @@ public interface ThrowingBiConsumer<T, U, E extends Exception> {
} }
public static <T, U, E extends Exception> ThrowingBiConsumer<T, U, E> concat( public static <T, U, E extends Exception> ThrowingBiConsumer<T, U, E> concat(
ThrowingBiConsumer<? super T, ? super U, ? extends E> first, ThrowingBiConsumer<? super T, ? super U, ? extends E> first,
ThrowingBiConsumer<? super T, ? super U, ? extends E> second ThrowingBiConsumer<? super T, ? super U, ? extends E> second) {
) { return (t, u) -> {
first.accept(t, u);
second.accept(t, u);
};
}
public static <T, U, E extends Exception> ThrowingBiConsumer<T, U, E> concat(BiConsumer<? super T, ? super U> first,
ThrowingBiConsumer<? super T, ? super U, E> second) {
return (t, u) -> { return (t, u) -> {
first.accept(t, u); first.accept(t, u);
second.accept(t, u); second.accept(t, u);
@ -54,19 +61,7 @@ public interface ThrowingBiConsumer<T, U, E extends Exception> {
} }
public static <T, U, E extends Exception> ThrowingBiConsumer<T, U, E> concat( public static <T, U, E extends Exception> ThrowingBiConsumer<T, U, E> concat(
BiConsumer<? super T, ? super U> first, ThrowingBiConsumer<? super T, ? super U, E> first, BiConsumer<? super T, ? super U> second) {
ThrowingBiConsumer<? super T, ? super U, E> second
) {
return (t, u) -> {
first.accept(t, u);
second.accept(t, u);
};
}
public static <T, U, E extends Exception> ThrowingBiConsumer<T, U, E> concat(
ThrowingBiConsumer<? super T, ? super U, E> first,
BiConsumer<? super T, ? super U> second
) {
return (t, u) -> { return (t, u) -> {
first.accept(t, u); first.accept(t, u);
second.accept(t, u); second.accept(t, u);

View File

@ -15,7 +15,7 @@
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>. * along with this program. If not, see <https://www.gnu.org/licenses/>.
*/ */
package ru.windcorp.jputil.functions; package ru.windcorp.jputil.functions;
import java.util.function.BiConsumer; import java.util.function.BiConsumer;
@ -39,30 +39,24 @@ public interface ThrowingConsumer<T, E extends Exception> {
}; };
} }
public static <T, E extends Exception> ThrowingConsumer<T, E> concat( public static <T, E extends Exception> ThrowingConsumer<T, E> concat(ThrowingConsumer<? super T, ? extends E> first,
ThrowingConsumer<? super T, ? extends E> first, ThrowingConsumer<? super T, ? extends E> second) {
ThrowingConsumer<? super T, ? extends E> second
) {
return t -> { return t -> {
first.accept(t); first.accept(t);
second.accept(t); second.accept(t);
}; };
} }
public static <T, E extends Exception> ThrowingConsumer<T, E> concat( public static <T, E extends Exception> ThrowingConsumer<T, E> concat(Consumer<? super T> first,
Consumer<? super T> first, ThrowingConsumer<? super T, ? extends E> second) {
ThrowingConsumer<? super T, ? extends E> second
) {
return t -> { return t -> {
first.accept(t); first.accept(t);
second.accept(t); second.accept(t);
}; };
} }
public static <T, E extends Exception> ThrowingConsumer<T, E> concat( public static <T, E extends Exception> ThrowingConsumer<T, E> concat(ThrowingConsumer<? super T, ? extends E> first,
ThrowingConsumer<? super T, ? extends E> first, Consumer<? super T> second) {
Consumer<? super T> second
) {
return t -> { return t -> {
first.accept(t); first.accept(t);
second.accept(t); second.accept(t);

View File

@ -15,7 +15,7 @@
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>. * along with this program. If not, see <https://www.gnu.org/licenses/>.
*/ */
package ru.windcorp.jputil.functions; package ru.windcorp.jputil.functions;
import java.util.function.BiConsumer; import java.util.function.BiConsumer;
@ -28,10 +28,8 @@ public interface ThrowingFunction<T, R, E extends Exception> {
R apply(T t) throws E; R apply(T t) throws E;
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
default Function<T, R> withHandler( default Function<T, R> withHandler(BiConsumer<? super T, ? super E> handler,
BiConsumer<? super T, ? super E> handler, Function<? super T, ? extends R> value) {
Function<? super T, ? extends R> value
) {
return t -> { return t -> {
try { try {
return apply(t); return apply(t);
@ -58,23 +56,18 @@ public interface ThrowingFunction<T, R, E extends Exception> {
} }
public static <T, R, I, E extends Exception> ThrowingFunction<T, R, E> compose( public static <T, R, I, E extends Exception> ThrowingFunction<T, R, E> compose(
ThrowingFunction<? super T, I, ? extends E> first, ThrowingFunction<? super T, I, ? extends E> first,
ThrowingFunction<? super I, ? extends R, ? extends E> second ThrowingFunction<? super I, ? extends R, ? extends E> second) {
) { return t -> second.apply(first.apply(t));
}
public static <T, R, I, E extends Exception> ThrowingFunction<T, R, E> compose(Function<? super T, I> first,
ThrowingFunction<? super I, ? extends R, E> second) {
return t -> second.apply(first.apply(t)); return t -> second.apply(first.apply(t));
} }
public static <T, R, I, E extends Exception> ThrowingFunction<T, R, E> compose( public static <T, R, I, E extends Exception> ThrowingFunction<T, R, E> compose(
Function<? super T, I> first, ThrowingFunction<? super T, I, E> first, Function<? super I, ? extends R> second) {
ThrowingFunction<? super I, ? extends R, E> second
) {
return t -> second.apply(first.apply(t));
}
public static <T, R, I, E extends Exception> ThrowingFunction<T, R, E> compose(
ThrowingFunction<? super T, I, E> first,
Function<? super I, ? extends R> second
) {
return t -> second.apply(first.apply(t)); return t -> second.apply(first.apply(t));
} }

View File

@ -15,7 +15,7 @@
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>. * along with this program. If not, see <https://www.gnu.org/licenses/>.
*/ */
package ru.windcorp.jputil.functions; package ru.windcorp.jputil.functions;
import java.util.function.Consumer; import java.util.function.Consumer;
@ -38,10 +38,8 @@ public interface ThrowingRunnable<E extends Exception> {
}; };
} }
public static <E extends Exception> ThrowingRunnable<E> concat( public static <E extends Exception> ThrowingRunnable<E> concat(ThrowingRunnable<? extends E> first,
ThrowingRunnable<? extends E> first, ThrowingRunnable<? extends E> second) {
ThrowingRunnable<? extends E> second
) {
return () -> { return () -> {
first.run(); first.run();
second.run(); second.run();

View File

@ -15,7 +15,7 @@
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>. * along with this program. If not, see <https://www.gnu.org/licenses/>.
*/ */
package ru.windcorp.jputil.functions; package ru.windcorp.jputil.functions;
import java.util.function.Consumer; import java.util.function.Consumer;

View File

@ -15,7 +15,7 @@
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>. * along with this program. If not, see <https://www.gnu.org/licenses/>.
*/ */
package ru.windcorp.jputil.iterators; package ru.windcorp.jputil.iterators;
import java.util.Iterator; import java.util.Iterator;

View File

@ -15,7 +15,7 @@
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>. * along with this program. If not, see <https://www.gnu.org/licenses/>.
*/ */
package ru.windcorp.jputil.iterators; package ru.windcorp.jputil.iterators;
import java.util.Iterator; import java.util.Iterator;

View File

@ -15,7 +15,7 @@
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>. * along with this program. If not, see <https://www.gnu.org/licenses/>.
*/ */
package ru.windcorp.jputil.iterators; package ru.windcorp.jputil.iterators;
import java.util.Iterator; import java.util.Iterator;

View File

@ -15,7 +15,7 @@
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>. * along with this program. If not, see <https://www.gnu.org/licenses/>.
*/ */
package ru.windcorp.jputil.iterators; package ru.windcorp.jputil.iterators;
import java.util.Iterator; import java.util.Iterator;
@ -49,10 +49,8 @@ public class RangeIterator<E> implements Iterator<E> {
public E next() { public E next() {
update(); update();
if (nextIndex >= from + amount) { if (nextIndex >= from + amount) {
throw new NoSuchElementException( throw new NoSuchElementException("RangeIterator about to retrieve element " + nextIndex
"RangeIterator about to retrieve element " + nextIndex + " which exceeds upper boundary " + (from + amount));
+ " which exceeds upper boundary " + (from + amount)
);
} }
E result = parent.next(); E result = parent.next();

View File

@ -15,7 +15,7 @@
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>. * along with this program. If not, see <https://www.gnu.org/licenses/>.
*/ */
package ru.windcorp.jputil.iterators; package ru.windcorp.jputil.iterators;
import java.util.ArrayList; import java.util.ArrayList;

View File

@ -15,7 +15,7 @@
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>. * along with this program. If not, see <https://www.gnu.org/licenses/>.
*/ */
package ru.windcorp.jputil.selectors; package ru.windcorp.jputil.selectors;
public abstract class AbstractSelectorOperator implements SelectorOperator { public abstract class AbstractSelectorOperator implements SelectorOperator {

View File

@ -15,7 +15,7 @@
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>. * along with this program. If not, see <https://www.gnu.org/licenses/>.
*/ */
package ru.windcorp.jputil.selectors; package ru.windcorp.jputil.selectors;
import ru.windcorp.jputil.SyntaxException; import ru.windcorp.jputil.SyntaxException;

View File

@ -15,7 +15,7 @@
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>. * along with this program. If not, see <https://www.gnu.org/licenses/>.
*/ */
package ru.windcorp.jputil.selectors; package ru.windcorp.jputil.selectors;
import ru.windcorp.jputil.SyntaxException; import ru.windcorp.jputil.SyntaxException;

View File

@ -15,7 +15,7 @@
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>. * along with this program. If not, see <https://www.gnu.org/licenses/>.
*/ */
package ru.windcorp.jputil.selectors; package ru.windcorp.jputil.selectors;
import java.util.Deque; import java.util.Deque;

View File

@ -15,7 +15,7 @@
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>. * along with this program. If not, see <https://www.gnu.org/licenses/>.
*/ */
package ru.windcorp.jputil.selectors; package ru.windcorp.jputil.selectors;
import java.util.Deque; import java.util.Deque;

View File

@ -15,7 +15,7 @@
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>. * along with this program. If not, see <https://www.gnu.org/licenses/>.
*/ */
package ru.windcorp.jputil.selectors; package ru.windcorp.jputil.selectors;
import java.util.Deque; import java.util.Deque;

View File

@ -15,7 +15,7 @@
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>. * along with this program. If not, see <https://www.gnu.org/licenses/>.
*/ */
package ru.windcorp.jputil.selectors; package ru.windcorp.jputil.selectors;
import java.util.Deque; import java.util.Deque;

View File

@ -15,7 +15,7 @@
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>. * along with this program. If not, see <https://www.gnu.org/licenses/>.
*/ */
package ru.windcorp.jputil.selectors; package ru.windcorp.jputil.selectors;
import java.util.Deque; import java.util.Deque;

View File

@ -15,7 +15,7 @@
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>. * along with this program. If not, see <https://www.gnu.org/licenses/>.
*/ */
package ru.windcorp.jputil.selectors; package ru.windcorp.jputil.selectors;
import java.util.function.Predicate; import java.util.function.Predicate;

View File

@ -15,7 +15,7 @@
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>. * along with this program. If not, see <https://www.gnu.org/licenses/>.
*/ */
package ru.windcorp.jputil.selectors; package ru.windcorp.jputil.selectors;
import java.util.function.Predicate; import java.util.function.Predicate;

View File

@ -15,7 +15,7 @@
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>. * along with this program. If not, see <https://www.gnu.org/licenses/>.
*/ */
package ru.windcorp.jputil.selectors; package ru.windcorp.jputil.selectors;
import java.util.Deque; import java.util.Deque;

View File

@ -15,7 +15,7 @@
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>. * along with this program. If not, see <https://www.gnu.org/licenses/>.
*/ */
package ru.windcorp.jputil.selectors; package ru.windcorp.jputil.selectors;
import java.util.ArrayList; import java.util.ArrayList;
@ -37,7 +37,7 @@ public class SelectorSystem<T> {
private final Collection<Selector<T>> selectors = Collections.synchronizedCollection(new ArrayList<Selector<T>>()); private final Collection<Selector<T>> selectors = Collections.synchronizedCollection(new ArrayList<Selector<T>>());
private final Collection<SelectorOperator> operators = Collections private final Collection<SelectorOperator> operators = Collections
.synchronizedCollection(new ArrayList<SelectorOperator>()); .synchronizedCollection(new ArrayList<SelectorOperator>());
private String stackPrefix = null; private String stackPrefix = null;

View File

@ -15,7 +15,7 @@
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>. * along with this program. If not, see <https://www.gnu.org/licenses/>.
*/ */
package ru.windcorp.progressia; package ru.windcorp.progressia;
public class Progressia { public class Progressia {

View File

@ -15,7 +15,7 @@
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>. * along with this program. If not, see <https://www.gnu.org/licenses/>.
*/ */
package ru.windcorp.progressia; package ru.windcorp.progressia;
import ru.windcorp.progressia.common.util.crash.CrashReports; import ru.windcorp.progressia.common.util.crash.CrashReports;

View File

@ -15,7 +15,7 @@
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>. * along with this program. If not, see <https://www.gnu.org/licenses/>.
*/ */
package ru.windcorp.progressia; package ru.windcorp.progressia;
public interface Proxy { public interface Proxy {

View File

@ -15,7 +15,7 @@
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>. * along with this program. If not, see <https://www.gnu.org/licenses/>.
*/ */
package ru.windcorp.progressia.client; package ru.windcorp.progressia.client;
import ru.windcorp.progressia.client.comms.DefaultClientCommsListener; import ru.windcorp.progressia.client.comms.DefaultClientCommsListener;
@ -24,7 +24,7 @@ import ru.windcorp.progressia.client.graphics.world.Camera;
import ru.windcorp.progressia.client.graphics.world.EntityAnchor; import ru.windcorp.progressia.client.graphics.world.EntityAnchor;
import ru.windcorp.progressia.client.graphics.world.LocalPlayer; import ru.windcorp.progressia.client.graphics.world.LocalPlayer;
import ru.windcorp.progressia.client.world.WorldRender; import ru.windcorp.progressia.client.world.WorldRender;
import ru.windcorp.progressia.common.world.WorldData; import ru.windcorp.progressia.common.world.DefaultWorldData;
import ru.windcorp.progressia.common.world.entity.EntityData; import ru.windcorp.progressia.common.world.entity.EntityData;
public class Client { public class Client {
@ -36,7 +36,7 @@ public class Client {
private final ServerCommsChannel comms; private final ServerCommsChannel comms;
public Client(WorldData world, ServerCommsChannel comms) { public Client(DefaultWorldData world, ServerCommsChannel comms) {
this.world = new WorldRender(world, this); this.world = new WorldRender(world, this);
this.comms = comms; this.comms = comms;
@ -69,11 +69,7 @@ public class Client {
return; return;
} }
getCamera().setAnchor( getCamera().setAnchor(new EntityAnchor(getWorld().getEntityRenderable(entity)));
new EntityAnchor(
getWorld().getEntityRenderable(entity)
)
);
} }
} }

View File

@ -15,7 +15,7 @@
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>. * along with this program. If not, see <https://www.gnu.org/licenses/>.
*/ */
package ru.windcorp.progressia.client; package ru.windcorp.progressia.client;
import ru.windcorp.progressia.Proxy; import ru.windcorp.progressia.Proxy;
@ -42,10 +42,8 @@ public class ClientProxy implements Proxy {
try { try {
RenderTaskQueue.waitAndInvoke(FlatRenderProgram::init); RenderTaskQueue.waitAndInvoke(FlatRenderProgram::init);
RenderTaskQueue.waitAndInvoke(WorldRenderProgram::init); RenderTaskQueue.waitAndInvoke(WorldRenderProgram::init);
RenderTaskQueue.waitAndInvoke( RenderTaskQueue.waitAndInvoke(() -> Typefaces
() -> Typefaces .setDefault(GNUUnifontLoader.load(ResourceManager.getResource("assets/unifont-13.0.03.hex.gz"))));
.setDefault(GNUUnifontLoader.load(ResourceManager.getResource("assets/unifont-13.0.03.hex.gz")))
);
} catch (InterruptedException e) { } catch (InterruptedException e) {
throw CrashReports.report(e, "ClientProxy failed"); throw CrashReports.report(e, "ClientProxy failed");
} }
@ -60,7 +58,7 @@ public class ClientProxy implements Proxy {
ServerState.startServer(); ServerState.startServer();
ClientState.connectToLocalServer(); ClientState.connectToLocalServer();
TestMusicPlayer.start(); TestMusicPlayer.start();
} }

View File

@ -15,13 +15,13 @@
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>. * along with this program. If not, see <https://www.gnu.org/licenses/>.
*/ */
package ru.windcorp.progressia.client; package ru.windcorp.progressia.client;
import ru.windcorp.progressia.client.comms.localhost.LocalServerCommsChannel; import ru.windcorp.progressia.client.comms.localhost.LocalServerCommsChannel;
import ru.windcorp.progressia.client.graphics.GUI; import ru.windcorp.progressia.client.graphics.GUI;
import ru.windcorp.progressia.client.graphics.world.LayerWorld; import ru.windcorp.progressia.client.graphics.world.LayerWorld;
import ru.windcorp.progressia.common.world.WorldData; import ru.windcorp.progressia.common.world.DefaultWorldData;
import ru.windcorp.progressia.server.ServerState; import ru.windcorp.progressia.server.ServerState;
import ru.windcorp.progressia.test.LayerAbout; import ru.windcorp.progressia.test.LayerAbout;
import ru.windcorp.progressia.test.LayerTestUI; import ru.windcorp.progressia.test.LayerTestUI;
@ -41,11 +41,9 @@ public class ClientState {
public static void connectToLocalServer() { public static void connectToLocalServer() {
WorldData world = new WorldData(); DefaultWorldData world = new DefaultWorldData();
LocalServerCommsChannel channel = new LocalServerCommsChannel( LocalServerCommsChannel channel = new LocalServerCommsChannel(ServerState.getInstance());
ServerState.getInstance()
);
Client client = new Client(world, channel); Client client = new Client(world, channel);

View File

@ -15,7 +15,7 @@
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>. * along with this program. If not, see <https://www.gnu.org/licenses/>.
*/ */
package ru.windcorp.progressia.client; package ru.windcorp.progressia.client;
import ru.windcorp.progressia.ProgressiaLauncher; import ru.windcorp.progressia.ProgressiaLauncher;

View File

@ -15,7 +15,7 @@
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>. * along with this program. If not, see <https://www.gnu.org/licenses/>.
*/ */
package ru.windcorp.progressia.client.audio; package ru.windcorp.progressia.client.audio;
public enum AudioFormat { public enum AudioFormat {

View File

@ -15,7 +15,7 @@
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>. * along with this program. If not, see <https://www.gnu.org/licenses/>.
*/ */
package ru.windcorp.progressia.client.audio; package ru.windcorp.progressia.client.audio;
import org.lwjgl.openal.*; import org.lwjgl.openal.*;
@ -43,10 +43,7 @@ public class AudioManager {
private static Speaker musicSpeaker; private static Speaker musicSpeaker;
public static void initAL() { public static void initAL() {
String defaultDeviceName = alcGetString( String defaultDeviceName = alcGetString(0, ALC_DEFAULT_DEVICE_SPECIFIER);
0,
ALC_DEFAULT_DEVICE_SPECIFIER
);
device = alcOpenDevice(defaultDeviceName); device = alcOpenDevice(defaultDeviceName);
@ -75,10 +72,7 @@ public class AudioManager {
lastSoundIndex = 0; lastSoundIndex = 0;
} }
speaker = soundSpeakers.get(lastSoundIndex); speaker = soundSpeakers.get(lastSoundIndex);
} while ( } while (speaker.getState().equals(Speaker.State.PLAYING_LOOP));
speaker.getState()
.equals(Speaker.State.PLAYING_LOOP)
);
return speaker; return speaker;
} }

View File

@ -21,9 +21,9 @@ import ru.windcorp.progressia.client.audio.backend.SoundType;
import ru.windcorp.progressia.common.util.namespaces.NamespacedInstanceRegistry; import ru.windcorp.progressia.common.util.namespaces.NamespacedInstanceRegistry;
public class AudioRegistry extends NamespacedInstanceRegistry<SoundType> { public class AudioRegistry extends NamespacedInstanceRegistry<SoundType> {
private static final AudioRegistry INSTANCE = new AudioRegistry(); private static final AudioRegistry INSTANCE = new AudioRegistry();
/** /**
* @return the instance * @return the instance
*/ */

View File

@ -15,7 +15,7 @@
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>. * along with this program. If not, see <https://www.gnu.org/licenses/>.
*/ */
package ru.windcorp.progressia.client.audio; package ru.windcorp.progressia.client.audio;
import ru.windcorp.progressia.common.resource.ResourceManager; import ru.windcorp.progressia.common.resource.ResourceManager;
@ -29,10 +29,7 @@ public class AudioSystem {
} }
static void loadAudioData() { static void loadAudioData() {
AudioManager.loadSound( AudioManager.loadSound(ResourceManager.getResource("assets/sounds/block_destroy_clap.ogg"),
ResourceManager.getResource("assets/sounds/block_destroy_clap.ogg"), "Progressia:BlockDestroy", AudioFormat.MONO);
"Progressia:BlockDestroy",
AudioFormat.MONO
);
} }
} }

View File

@ -15,18 +15,15 @@
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>. * along with this program. If not, see <https://www.gnu.org/licenses/>.
*/ */
package ru.windcorp.progressia.client.audio; package ru.windcorp.progressia.client.audio;
import glm.vec._3.Vec3; import glm.vec._3.Vec3;
import ru.windcorp.progressia.client.audio.backend.SoundType; import ru.windcorp.progressia.client.audio.backend.SoundType;
import ru.windcorp.progressia.client.audio.backend.Speaker; import ru.windcorp.progressia.client.audio.backend.Speaker;
public class Music public class Music extends Sound {
extends Sound {
public Music(SoundType soundType, int timeLength, float pitch, float gain) { public Music(SoundType soundType, int timeLength, float pitch, float gain) {
super(soundType, timeLength, new Vec3(), new Vec3(), pitch, gain); super(soundType, timeLength, new Vec3(), new Vec3(), pitch, gain);
} }
@ -47,7 +44,7 @@ public class Music
protected Speaker initSpeaker() { protected Speaker initSpeaker() {
return AudioManager.initMusicSpeaker(soundType); return AudioManager.initMusicSpeaker(soundType);
} }
@Override @Override
public void setPosition(Vec3 position) { public void setPosition(Vec3 position) {
throw new UnsupportedOperationException(); throw new UnsupportedOperationException();

View File

@ -15,7 +15,7 @@
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>. * along with this program. If not, see <https://www.gnu.org/licenses/>.
*/ */
package ru.windcorp.progressia.client.audio; package ru.windcorp.progressia.client.audio;
import glm.vec._3.Vec3; import glm.vec._3.Vec3;
@ -29,9 +29,9 @@ public class Sound {
protected float pitch = 1.0f; protected float pitch = 1.0f;
protected float gain = 1.0f; protected float gain = 1.0f;
protected int timeLength = 0; protected int timeLength = 0;
protected SoundType soundType; protected SoundType soundType;
public Sound(SoundType soundType) { public Sound(SoundType soundType) {
this.soundType = soundType; this.soundType = soundType;
} }
@ -39,37 +39,23 @@ public class Sound {
public Sound(String id) { public Sound(String id) {
this(AudioRegistry.getInstance().get(id)); this(AudioRegistry.getInstance().get(id));
} }
public Sound( public Sound(String id, int timeLength, Vec3 position, Vec3 velocity, float pitch, float gain) {
String id,
int timeLength,
Vec3 position,
Vec3 velocity,
float pitch,
float gain
) {
this(id); this(id);
this.position = position; this.position = position;
this.velocity = velocity; this.velocity = velocity;
this.pitch = pitch; this.pitch = pitch;
this.gain = gain; this.gain = gain;
} }
public Sound( public Sound(SoundType soundType, int timeLength, Vec3 position, Vec3 velocity, float pitch, float gain) {
SoundType soundType,
int timeLength,
Vec3 position,
Vec3 velocity,
float pitch,
float gain
) {
this(soundType); this(soundType);
this.position = position; this.position = position;
this.velocity = velocity; this.velocity = velocity;
this.pitch = pitch; this.pitch = pitch;
this.gain = gain; this.gain = gain;
} }
protected Speaker initSpeaker() { protected Speaker initSpeaker() {
return AudioManager.initSpeaker(soundType); return AudioManager.initSpeaker(soundType);
} }
@ -119,7 +105,7 @@ public class Sound {
public float getPitch() { public float getPitch() {
return pitch; return pitch;
} }
public double getDuration() { public double getDuration() {
return soundType.getDuration(); return soundType.getDuration();
} }

View File

@ -15,7 +15,7 @@
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>. * along with this program. If not, see <https://www.gnu.org/licenses/>.
*/ */
package ru.windcorp.progressia.client.audio.backend; package ru.windcorp.progressia.client.audio.backend;
import org.lwjgl.BufferUtils; import org.lwjgl.BufferUtils;
@ -39,12 +39,7 @@ public class AudioReader {
ShortBuffer rawAudio = decodeVorbis(resource, channelBuffer, rateBuffer); ShortBuffer rawAudio = decodeVorbis(resource, channelBuffer, rateBuffer);
return new SoundType( return new SoundType(id, rawAudio, format, rateBuffer.get(0));
id,
rawAudio,
format,
rateBuffer.get(0)
);
} }
public static SoundType readAsMono(Resource resource, String id) { public static SoundType readAsMono(Resource resource, String id) {
@ -55,15 +50,7 @@ public class AudioReader {
return readAsSpecified(resource, id, AL_FORMAT_STEREO16); return readAsSpecified(resource, id, AL_FORMAT_STEREO16);
} }
private static ShortBuffer decodeVorbis( private static ShortBuffer decodeVorbis(Resource dataToDecode, IntBuffer channelsBuffer, IntBuffer rateBuffer) {
Resource dataToDecode, return stb_vorbis_decode_memory(dataToDecode.readAsBytes(), channelsBuffer, rateBuffer);
IntBuffer channelsBuffer,
IntBuffer rateBuffer
) {
return stb_vorbis_decode_memory(
dataToDecode.readAsBytes(),
channelsBuffer,
rateBuffer
);
} }
} }

View File

@ -15,7 +15,7 @@
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>. * along with this program. If not, see <https://www.gnu.org/licenses/>.
*/ */
package ru.windcorp.progressia.client.audio.backend; package ru.windcorp.progressia.client.audio.backend;
import glm.vec._3.Vec3; import glm.vec._3.Vec3;
@ -55,9 +55,8 @@ public class Listener {
if (isInWorld) { if (isInWorld) {
if (wasInWorld) { if (wasInWorld) {
velocity.set(camera.getLastAnchorPosition()).sub(position).div( velocity.set(camera.getLastAnchorPosition()).sub(position)
(float) GraphicsInterface.getFrameLength() .div((float) GraphicsInterface.getFrameLength());
);
} else { } else {
// If !wasInWorld, previous position is nonsence. Assume 0. // If !wasInWorld, previous position is nonsence. Assume 0.
velocity.set(0); velocity.set(0);
@ -72,9 +71,9 @@ public class Listener {
} }
/* /*
* Only apply if there is a chance that params changed. * Only apply if there is a chance that params changed. This can only
* This can only happen if we are in world now (isInWorld) or we just * happen if we are in world now (isInWorld) or we just left world
* left world (wasInWorld, then we need to reset). * (wasInWorld, then we need to reset).
*/ */
if (isInWorld || wasInWorld) { if (isInWorld || wasInWorld) {
applyParams(); applyParams();
@ -91,17 +90,7 @@ public class Listener {
private void applyParams() { private void applyParams() {
alListener3f(AL_POSITION, position.x, position.y, position.z); alListener3f(AL_POSITION, position.x, position.y, position.z);
alListener3f(AL_VELOCITY, velocity.x, velocity.y, velocity.z); alListener3f(AL_VELOCITY, velocity.x, velocity.y, velocity.z);
alListenerfv( alListenerfv(AL_ORIENTATION, new float[] { oriAt.x, oriAt.y, oriAt.z, oriUp.x, oriUp.y, oriUp.z });
AL_ORIENTATION,
new float[] {
oriAt.x,
oriAt.y,
oriAt.z,
oriUp.x,
oriUp.y,
oriUp.z
}
);
} }
} }

View File

@ -15,7 +15,7 @@
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>. * along with this program. If not, see <https://www.gnu.org/licenses/>.
*/ */
package ru.windcorp.progressia.client.audio.backend; package ru.windcorp.progressia.client.audio.backend;
import ru.windcorp.progressia.common.util.namespaces.Namespaced; import ru.windcorp.progressia.common.util.namespaces.Namespaced;
@ -34,12 +34,7 @@ public class SoundType extends Namespaced {
private int audioBuffer; private int audioBuffer;
private double duration; private double duration;
public SoundType( public SoundType(String id, ShortBuffer rawAudio, int format, int sampleRate) {
String id,
ShortBuffer rawAudio,
int format,
int sampleRate
) {
super(id); super(id);
this.rawAudio = rawAudio; this.rawAudio = rawAudio;
this.sampleRate = sampleRate; this.sampleRate = sampleRate;
@ -56,7 +51,7 @@ public class SoundType extends Namespaced {
public void initSpeaker(Speaker speaker) { public void initSpeaker(Speaker speaker) {
speaker.setAudioData(audioBuffer); speaker.setAudioData(audioBuffer);
} }
public double getDuration() { public double getDuration() {
return duration; return duration;
} }

View File

@ -15,7 +15,7 @@
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>. * along with this program. If not, see <https://www.gnu.org/licenses/>.
*/ */
package ru.windcorp.progressia.client.audio.backend; package ru.windcorp.progressia.client.audio.backend;
import glm.vec._3.Vec3; import glm.vec._3.Vec3;
@ -24,9 +24,7 @@ import static org.lwjgl.openal.AL11.*;
public class Speaker { public class Speaker {
public enum State { public enum State {
NOT_PLAYING, NOT_PLAYING, PLAYING, PLAYING_LOOP
PLAYING,
PLAYING_LOOP
} }
// Buffers // Buffers
@ -49,13 +47,7 @@ public class Speaker {
setAudioData(audioData); setAudioData(audioData);
} }
public Speaker( public Speaker(int audioData, Vec3 position, Vec3 velocity, float pitch, float gain) {
int audioData,
Vec3 position,
Vec3 velocity,
float pitch,
float gain
) {
setAudioData(audioData); setAudioData(audioData);
setPosition(position); setPosition(position);
setVelocity(velocity); setVelocity(velocity);
@ -63,12 +55,7 @@ public class Speaker {
setGain(gain); setGain(gain);
} }
public Speaker( public Speaker(Vec3 position, Vec3 velocity, float pitch, float gain) {
Vec3 position,
Vec3 velocity,
float pitch,
float gain
) {
setPosition(position); setPosition(position);
setVelocity(velocity); setVelocity(velocity);
setPitch(pitch); setPitch(pitch);

View File

@ -15,7 +15,7 @@
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>. * along with this program. If not, see <https://www.gnu.org/licenses/>.
*/ */
package ru.windcorp.progressia.client.comms; package ru.windcorp.progressia.client.comms;
import java.io.IOException; import java.io.IOException;
@ -39,9 +39,7 @@ public class DefaultClientCommsListener implements CommsListener {
@Override @Override
public void onPacketReceived(Packet packet) { public void onPacketReceived(Packet packet) {
if (packet instanceof PacketAffectWorld) { if (packet instanceof PacketAffectWorld) {
((PacketAffectWorld) packet).apply( ((PacketAffectWorld) packet).apply(getClient().getWorld().getData());
getClient().getWorld().getData()
);
} else if (packet instanceof PacketSetLocalPlayer) { } else if (packet instanceof PacketSetLocalPlayer) {
setLocalPlayer((PacketSetLocalPlayer) packet); setLocalPlayer((PacketSetLocalPlayer) packet);
} }

View File

@ -15,7 +15,7 @@
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>. * along with this program. If not, see <https://www.gnu.org/licenses/>.
*/ */
package ru.windcorp.progressia.client.comms; package ru.windcorp.progressia.client.comms;
import ru.windcorp.progressia.common.comms.CommsChannel; import ru.windcorp.progressia.common.comms.CommsChannel;

View File

@ -15,7 +15,7 @@
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>. * along with this program. If not, see <https://www.gnu.org/licenses/>.
*/ */
package ru.windcorp.progressia.client.comms.controls; package ru.windcorp.progressia.client.comms.controls;
import ru.windcorp.progressia.common.util.namespaces.Namespaced; import ru.windcorp.progressia.common.util.namespaces.Namespaced;

View File

@ -15,7 +15,7 @@
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>. * along with this program. If not, see <https://www.gnu.org/licenses/>.
*/ */
package ru.windcorp.progressia.client.comms.controls; package ru.windcorp.progressia.client.comms.controls;
import ru.windcorp.progressia.client.graphics.input.InputEvent; import ru.windcorp.progressia.client.graphics.input.InputEvent;

View File

@ -15,7 +15,7 @@
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>. * along with this program. If not, see <https://www.gnu.org/licenses/>.
*/ */
package ru.windcorp.progressia.client.comms.controls; package ru.windcorp.progressia.client.comms.controls;
import java.util.function.BiConsumer; import java.util.function.BiConsumer;
@ -33,17 +33,12 @@ public class ControlTriggerLambda extends ControlTriggerInputBased {
private final Predicate<InputEvent> predicate; private final Predicate<InputEvent> predicate;
private final BiConsumer<InputEvent, ControlData> dataWriter; private final BiConsumer<InputEvent, ControlData> dataWriter;
public ControlTriggerLambda( public ControlTriggerLambda(String id, Predicate<InputEvent> predicate,
String id, BiConsumer<InputEvent, ControlData> dataWriter) {
Predicate<InputEvent> predicate,
BiConsumer<InputEvent, ControlData> dataWriter
) {
super(id); super(id);
this.packetId = NamespacedUtil.getId( this.packetId = NamespacedUtil.getId(NamespacedUtil.getNamespace(id),
NamespacedUtil.getNamespace(id), "ControlKeyPress" + NamespacedUtil.getName(id));
"ControlKeyPress" + NamespacedUtil.getName(id)
);
this.predicate = predicate; this.predicate = predicate;
this.dataWriter = dataWriter; this.dataWriter = dataWriter;
@ -54,10 +49,7 @@ public class ControlTriggerLambda extends ControlTriggerInputBased {
if (!predicate.test(event)) if (!predicate.test(event))
return null; return null;
PacketControl packet = new PacketControl( PacketControl packet = new PacketControl(packetId, ControlDataRegistry.getInstance().create(getId()));
packetId,
ControlDataRegistry.getInstance().create(getId())
);
dataWriter.accept(event, packet.getControl()); dataWriter.accept(event, packet.getControl());

View File

@ -15,7 +15,7 @@
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>. * along with this program. If not, see <https://www.gnu.org/licenses/>.
*/ */
package ru.windcorp.progressia.client.comms.controls; package ru.windcorp.progressia.client.comms.controls;
import java.util.function.Consumer; import java.util.function.Consumer;
@ -29,11 +29,7 @@ public class ControlTriggerLocalLambda extends ControlTriggerInputBased {
private final Predicate<InputEvent> predicate; private final Predicate<InputEvent> predicate;
private final Consumer<InputEvent> action; private final Consumer<InputEvent> action;
public ControlTriggerLocalLambda( public ControlTriggerLocalLambda(String id, Predicate<InputEvent> predicate, Consumer<InputEvent> action) {
String id,
Predicate<InputEvent> predicate,
Consumer<InputEvent> action
) {
super(id); super(id);
this.predicate = predicate; this.predicate = predicate;

View File

@ -15,7 +15,7 @@
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>. * along with this program. If not, see <https://www.gnu.org/licenses/>.
*/ */
package ru.windcorp.progressia.client.comms.controls; package ru.windcorp.progressia.client.comms.controls;
import ru.windcorp.progressia.common.util.namespaces.NamespacedInstanceRegistry; import ru.windcorp.progressia.common.util.namespaces.NamespacedInstanceRegistry;

View File

@ -15,7 +15,7 @@
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>. * along with this program. If not, see <https://www.gnu.org/licenses/>.
*/ */
package ru.windcorp.progressia.client.comms.controls; package ru.windcorp.progressia.client.comms.controls;
import java.util.function.BiConsumer; import java.util.function.BiConsumer;
@ -27,122 +27,59 @@ import ru.windcorp.progressia.common.comms.controls.ControlData;
public class ControlTriggers { public class ControlTriggers {
public static ControlTriggerInputBased of( public static ControlTriggerInputBased of(String id, BiConsumer<InputEvent, ControlData> dataWriter,
String id, Predicate<InputEvent> predicate) {
BiConsumer<InputEvent, ControlData> dataWriter,
Predicate<InputEvent> predicate
) {
return new ControlTriggerLambda(id, predicate, dataWriter); return new ControlTriggerLambda(id, predicate, dataWriter);
} }
public static ControlTriggerInputBased of( public static ControlTriggerInputBased of(String id, Consumer<ControlData> dataWriter,
String id, Predicate<InputEvent> predicate) {
Consumer<ControlData> dataWriter, return of(id, (input, control) -> dataWriter.accept(control), predicate);
Predicate<InputEvent> predicate
) {
return of(
id,
(input, control) -> dataWriter.accept(control),
predicate
);
} }
public static ControlTriggerInputBased of( public static ControlTriggerInputBased of(String id, Predicate<InputEvent> predicate) {
String id, return of(id, (input, control) -> {
Predicate<InputEvent> predicate }, predicate);
) {
return of(
id,
(input, control) -> {
},
predicate
);
} }
@SafeVarargs @SafeVarargs
public static <I extends InputEvent> ControlTriggerInputBased of( public static <I extends InputEvent> ControlTriggerInputBased of(String id, Class<I> inputType,
String id, BiConsumer<I, ControlData> dataWriter, Predicate<I>... predicates) {
Class<I> inputType, return of(id, createCheckedDataWriter(inputType, dataWriter),
BiConsumer<I, ControlData> dataWriter, createCheckedCompoundPredicate(inputType, predicates));
Predicate<I>... predicates
) {
return of(
id,
createCheckedDataWriter(inputType, dataWriter),
createCheckedCompoundPredicate(inputType, predicates)
);
} }
@SafeVarargs @SafeVarargs
public static <I extends InputEvent> ControlTriggerInputBased of( public static <I extends InputEvent> ControlTriggerInputBased of(String id, Class<I> inputType,
String id, Consumer<ControlData> dataWriter, Predicate<I>... predicates) {
Class<I> inputType, return of(id, inputType, (input, control) -> dataWriter.accept(control), predicates);
Consumer<ControlData> dataWriter,
Predicate<I>... predicates
) {
return of(
id,
inputType,
(input, control) -> dataWriter.accept(control),
predicates
);
} }
@SafeVarargs @SafeVarargs
public static <I extends InputEvent> ControlTriggerInputBased of( public static <I extends InputEvent> ControlTriggerInputBased of(String id, Class<I> inputType,
String id, Predicate<I>... predicates) {
Class<I> inputType, return of(id, (input, control) -> {
Predicate<I>... predicates }, createCheckedCompoundPredicate(inputType, predicates));
) {
return of(
id,
(input, control) -> {
},
createCheckedCompoundPredicate(inputType, predicates)
);
} }
@SafeVarargs @SafeVarargs
public static ControlTriggerInputBased of( public static ControlTriggerInputBased of(String id, BiConsumer<InputEvent, ControlData> dataWriter,
String id, Predicate<InputEvent>... predicates) {
BiConsumer<InputEvent, ControlData> dataWriter, return of(id, InputEvent.class, dataWriter, predicates);
Predicate<InputEvent>... predicates
) {
return of(
id,
InputEvent.class,
dataWriter,
predicates
);
} }
@SafeVarargs @SafeVarargs
public static <I extends InputEvent> ControlTriggerInputBased of( public static <I extends InputEvent> ControlTriggerInputBased of(String id, Consumer<ControlData> dataWriter,
String id, Predicate<InputEvent>... predicates) {
Consumer<ControlData> dataWriter, return of(id, (input, control) -> dataWriter.accept(control), predicates);
Predicate<InputEvent>... predicates
) {
return of(
id,
(input, control) -> dataWriter.accept(control),
predicates
);
} }
@SafeVarargs @SafeVarargs
public static ControlTriggerInputBased of( public static ControlTriggerInputBased of(String id, Predicate<InputEvent>... predicates) {
String id, return of(id, InputEvent.class, (input, control) -> {
Predicate<InputEvent>... predicates }, predicates);
) {
return of(
id,
InputEvent.class,
(input, control) -> {
},
predicates
);
} }
// //
// //
/// ///
@ -156,101 +93,53 @@ public class ControlTriggers {
// //
// //
// //
public static ControlTriggerInputBased localOf( public static ControlTriggerInputBased localOf(String id, Consumer<InputEvent> action,
String id, Predicate<InputEvent> predicate) {
Consumer<InputEvent> action,
Predicate<InputEvent> predicate
) {
return new ControlTriggerLocalLambda(id, predicate, action); return new ControlTriggerLocalLambda(id, predicate, action);
} }
public static ControlTriggerInputBased localOf( public static ControlTriggerInputBased localOf(String id, Runnable action, Predicate<InputEvent> predicate) {
String id, return localOf(id, input -> action.run(), predicate);
Runnable action,
Predicate<InputEvent> predicate
) {
return localOf(
id,
input -> action.run(),
predicate
);
} }
@SafeVarargs @SafeVarargs
public static <I extends InputEvent> ControlTriggerInputBased localOf( public static <I extends InputEvent> ControlTriggerInputBased localOf(String id, Class<I> inputType,
String id, Consumer<I> action, Predicate<I>... predicates) {
Class<I> inputType, return localOf(id, createCheckedAction(inputType, action),
Consumer<I> action, createCheckedCompoundPredicate(inputType, predicates));
Predicate<I>... predicates
) {
return localOf(
id,
createCheckedAction(inputType, action),
createCheckedCompoundPredicate(inputType, predicates)
);
} }
@SafeVarargs @SafeVarargs
public static <I extends InputEvent> ControlTriggerInputBased localOf( public static <I extends InputEvent> ControlTriggerInputBased localOf(String id, Class<I> inputType,
String id, Runnable action, Predicate<I>... predicates) {
Class<I> inputType, return localOf(id, inputType, input -> action.run(), predicates);
Runnable action,
Predicate<I>... predicates
) {
return localOf(
id,
inputType,
input -> action.run(),
predicates
);
} }
@SafeVarargs @SafeVarargs
public static ControlTriggerInputBased localOf( public static ControlTriggerInputBased localOf(String id, Consumer<InputEvent> action,
String id, Predicate<InputEvent>... predicates) {
Consumer<InputEvent> action, return localOf(id, InputEvent.class, action, predicates);
Predicate<InputEvent>... predicates
) {
return localOf(
id,
InputEvent.class,
action,
predicates
);
} }
@SafeVarargs @SafeVarargs
public static <I extends InputEvent> ControlTriggerInputBased localOf( public static <I extends InputEvent> ControlTriggerInputBased localOf(String id, Runnable action,
String id, Predicate<InputEvent>... predicates) {
Runnable action, return of(id, input -> action.run(), predicates);
Predicate<InputEvent>... predicates
) {
return of(
id,
input -> action.run(),
predicates
);
} }
private static <I extends InputEvent> BiConsumer<InputEvent, ControlData> createCheckedDataWriter( private static <I extends InputEvent> BiConsumer<InputEvent, ControlData> createCheckedDataWriter(
Class<I> inputType, Class<I> inputType, BiConsumer<I, ControlData> dataWriter) {
BiConsumer<I, ControlData> dataWriter
) {
return (inputEvent, control) -> dataWriter.accept(inputType.cast(inputEvent), control); return (inputEvent, control) -> dataWriter.accept(inputType.cast(inputEvent), control);
} }
private static <I extends InputEvent> Consumer<InputEvent> createCheckedAction( private static <I extends InputEvent> Consumer<InputEvent> createCheckedAction(Class<I> inputType,
Class<I> inputType, Consumer<I> action) {
Consumer<I> action
) {
return inputEvent -> action.accept(inputType.cast(inputEvent)); return inputEvent -> action.accept(inputType.cast(inputEvent));
} }
private static <I extends InputEvent> Predicate<InputEvent> createCheckedCompoundPredicate( private static <I extends InputEvent> Predicate<InputEvent> createCheckedCompoundPredicate(Class<I> inputType,
Class<I> inputType, Predicate<I>[] predicates) {
Predicate<I>[] predicates
) {
return new CompoundCastPredicate<>(inputType, predicates); return new CompoundCastPredicate<>(inputType, predicates);
} }

View File

@ -15,7 +15,7 @@
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>. * along with this program. If not, see <https://www.gnu.org/licenses/>.
*/ */
package ru.windcorp.progressia.client.comms.controls; package ru.windcorp.progressia.client.comms.controls;
import ru.windcorp.progressia.client.Client; import ru.windcorp.progressia.client.Client;
@ -32,8 +32,7 @@ public class InputBasedControls {
this.client = client; this.client = client;
this.controls = ControlTriggerRegistry.getInstance().values().stream() this.controls = ControlTriggerRegistry.getInstance().values().stream()
.filter(ControlTriggerInputBased.class::isInstance) .filter(ControlTriggerInputBased.class::isInstance).toArray(ControlTriggerInputBased[]::new);
.toArray(ControlTriggerInputBased[]::new);
} }
public void handleInput(Input input) { public void handleInput(Input input) {

View File

@ -15,7 +15,7 @@
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>. * along with this program. If not, see <https://www.gnu.org/licenses/>.
*/ */
package ru.windcorp.progressia.client.comms.localhost; package ru.windcorp.progressia.client.comms.localhost;
import java.io.IOException; import java.io.IOException;

View File

@ -15,7 +15,7 @@
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>. * along with this program. If not, see <https://www.gnu.org/licenses/>.
*/ */
package ru.windcorp.progressia.client.comms.localhost; package ru.windcorp.progressia.client.comms.localhost;
import ru.windcorp.progressia.client.comms.ServerCommsChannel; import ru.windcorp.progressia.client.comms.ServerCommsChannel;
@ -34,11 +34,7 @@ public class LocalServerCommsChannel extends ServerCommsChannel {
public void connect(String login) { public void connect(String login) {
setState(State.CONNECTED); setState(State.CONNECTED);
this.localClient = new LocalClient( this.localClient = new LocalClient(server.getClientManager().grabClientId(), login, this);
server.getClientManager().grabClientId(),
login,
this
);
server.getClientManager().addClient(localClient); server.getClientManager().addClient(localClient);
} }

View File

@ -34,7 +34,13 @@ public class Colors {
DEBUG_BLUE = toVector(0xFF0000FF), DEBUG_BLUE = toVector(0xFF0000FF),
DEBUG_CYAN = toVector(0xFF00FFFF), DEBUG_CYAN = toVector(0xFF00FFFF),
DEBUG_MAGENTA = toVector(0xFFFF00FF), DEBUG_MAGENTA = toVector(0xFFFF00FF),
DEBUG_YELLOW = toVector(0xFFFFFF00); DEBUG_YELLOW = toVector(0xFFFFFF00),
LIGHT_GRAY = toVector(0xFFCBCBD0),
BLUE = toVector(0xFF37A2E6),
HOVER_BLUE = toVector(0xFFC3E4F7),
DISABLED_GRAY = toVector(0xFFE5E5E5),
DISABLED_BLUE = toVector(0xFFB2D8ED);
public static Vec4 toVector(int argb) { public static Vec4 toVector(int argb) {
return toVector(argb, new Vec4()); return toVector(argb, new Vec4());

View File

@ -15,7 +15,7 @@
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>. * along with this program. If not, see <https://www.gnu.org/licenses/>.
*/ */
package ru.windcorp.progressia.client.graphics; package ru.windcorp.progressia.client.graphics;
import java.util.ArrayList; import java.util.ArrayList;
@ -24,6 +24,7 @@ import java.util.List;
import com.google.common.eventbus.Subscribe; import com.google.common.eventbus.Subscribe;
import ru.windcorp.progressia.client.graphics.backend.GraphicsInterface;
import ru.windcorp.progressia.client.graphics.input.CursorEvent; import ru.windcorp.progressia.client.graphics.input.CursorEvent;
import ru.windcorp.progressia.client.graphics.input.FrameResizeEvent; import ru.windcorp.progressia.client.graphics.input.FrameResizeEvent;
import ru.windcorp.progressia.client.graphics.input.InputEvent; import ru.windcorp.progressia.client.graphics.input.InputEvent;
@ -42,7 +43,7 @@ public class GUI {
} }
private static final List<LayerStackModification> MODIFICATION_QUEUE = Collections private static final List<LayerStackModification> MODIFICATION_QUEUE = Collections
.synchronizedList(new ArrayList<>()); .synchronizedList(new ArrayList<>());
private static class ModifiableInput extends Input { private static class ModifiableInput extends Input {
@Override @Override
@ -57,15 +58,24 @@ public class GUI {
} }
public static void addBottomLayer(Layer layer) { public static void addBottomLayer(Layer layer) {
modify(layers -> layers.add(layer)); modify(layers -> {
layers.add(layer);
layer.onAdded();
});
} }
public static void addTopLayer(Layer layer) { public static void addTopLayer(Layer layer) {
modify(layers -> layers.add(0, layer)); modify(layers -> {
layers.add(0, layer);
layer.onAdded();
});
} }
public static void removeLayer(Layer layer) { public static void removeLayer(Layer layer) {
modify(layers -> layers.remove(layer)); modify(layers -> {
layers.remove(layer);
layer.onRemoved();
});
} }
private static void modify(LayerStackModification mod) { private static void modify(LayerStackModification mod) {
@ -78,12 +88,33 @@ public class GUI {
public static void render() { public static void render() {
synchronized (LAYERS) { synchronized (LAYERS) {
MODIFICATION_QUEUE.forEach(action -> action.affect(LAYERS));
MODIFICATION_QUEUE.clear(); if (!MODIFICATION_QUEUE.isEmpty()) {
MODIFICATION_QUEUE.forEach(action -> action.affect(LAYERS));
MODIFICATION_QUEUE.clear();
boolean isMouseCurrentlyCaptured = GraphicsInterface.isMouseCaptured();
Layer.CursorPolicy policy = Layer.CursorPolicy.REQUIRE;
for (Layer layer : LAYERS) {
Layer.CursorPolicy currentPolicy = layer.getCursorPolicy();
if (currentPolicy != Layer.CursorPolicy.INDIFFERENT) {
policy = currentPolicy;
break;
}
}
boolean shouldCaptureMouse = (policy == Layer.CursorPolicy.FORBID);
if (shouldCaptureMouse != isMouseCurrentlyCaptured) {
GraphicsInterface.setMouseCaptured(shouldCaptureMouse);
}
}
for (int i = LAYERS.size() - 1; i >= 0; --i) { for (int i = LAYERS.size() - 1; i >= 0; --i) {
LAYERS.get(i).render(); LAYERS.get(i).render();
} }
} }
} }

View File

@ -15,7 +15,7 @@
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>. * along with this program. If not, see <https://www.gnu.org/licenses/>.
*/ */
package ru.windcorp.progressia.client.graphics; package ru.windcorp.progressia.client.graphics;
import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicBoolean;
@ -30,15 +30,52 @@ public abstract class Layer {
private boolean hasInitialized = false; private boolean hasInitialized = false;
private final AtomicBoolean isValid = new AtomicBoolean(false); private final AtomicBoolean isValid = new AtomicBoolean(false);
/**
* Represents various requests that a {@link Layer} can make regarding the
* presence of a visible cursor. The value of the highest layer that is not
* {@link #INDIFFERENT} is used.
*/
public static enum CursorPolicy {
/**
* Require that a cursor is visible.
*/
REQUIRE,
/**
* The {@link Layer} should not affect the presence or absence of a
* visible cursor; lower layers should be consulted.
*/
INDIFFERENT,
/**
* Forbid a visible cursor.
*/
FORBID
}
private CursorPolicy cursorPolicy = CursorPolicy.INDIFFERENT;
public Layer(String name) { public Layer(String name) {
this.name = name; this.name = name;
} }
public String getName() {
return name;
}
@Override @Override
public String toString() { public String toString() {
return "Layer " + name; return "Layer " + name;
} }
public CursorPolicy getCursorPolicy() {
return cursorPolicy;
}
public void setCursorPolicy(CursorPolicy cursorPolicy) {
this.cursorPolicy = cursorPolicy;
}
void render() { void render() {
GraphicsInterface.startNextLayer(); GraphicsInterface.startNextLayer();
@ -78,5 +115,13 @@ public abstract class Layer {
protected int getHeight() { protected int getHeight() {
return GraphicsInterface.getFrameHeight(); return GraphicsInterface.getFrameHeight();
} }
protected void onAdded() {
// Do nothing
}
protected void onRemoved() {
// Do nothing
}
} }

View File

@ -15,7 +15,7 @@
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>. * along with this program. If not, see <https://www.gnu.org/licenses/>.
*/ */
package ru.windcorp.progressia.client.graphics.backend; package ru.windcorp.progressia.client.graphics.backend;
import java.util.ArrayDeque; import java.util.ArrayDeque;

View File

@ -15,7 +15,7 @@
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>. * along with this program. If not, see <https://www.gnu.org/licenses/>.
*/ */
package ru.windcorp.progressia.client.graphics.backend; package ru.windcorp.progressia.client.graphics.backend;
import glm.vec._2.i.Vec2i; import glm.vec._2.i.Vec2i;
@ -61,7 +61,7 @@ public class GraphicsBackend {
static void setOpenGLInitialized(boolean isOpenGLInitialized) { static void setOpenGLInitialized(boolean isOpenGLInitialized) {
GraphicsBackend.isOpenGLInitialized = isOpenGLInitialized; GraphicsBackend.isOpenGLInitialized = isOpenGLInitialized;
} }
public static void initialize() { public static void initialize() {
startRenderThread(); startRenderThread();
} }
@ -159,27 +159,14 @@ public class GraphicsBackend {
public static void setFullscreen() { public static void setFullscreen() {
GLFWVidMode vidmode = glfwGetVideoMode(glfwGetPrimaryMonitor()); GLFWVidMode vidmode = glfwGetVideoMode(glfwGetPrimaryMonitor());
glfwSetWindowMonitor( glfwSetWindowMonitor(getWindowHandle(), glfwGetPrimaryMonitor(), 0, 0, vidmode.width(), vidmode.height(), 0);
getWindowHandle(),
glfwGetPrimaryMonitor(),
0,
0,
vidmode.width(),
vidmode.height(),
0);
isFullscreen = true; isFullscreen = true;
} }
public static void setWindowed() { public static void setWindowed() {
GLFWVidMode vidmode = glfwGetVideoMode(glfwGetPrimaryMonitor()); GLFWVidMode vidmode = glfwGetVideoMode(glfwGetPrimaryMonitor());
glfwSetWindowMonitor( glfwSetWindowMonitor(getWindowHandle(), 0, (vidmode.width() - getFrameWidth()) / 2,
getWindowHandle(), (vidmode.height() - getFrameHeight()) / 2, getFrameWidth(), getFrameHeight(), 0);
0,
(vidmode.width() - getFrameWidth()) / 2,
(vidmode.height() - getFrameHeight()) / 2,
getFrameWidth(),
getFrameHeight(),
0);
isFullscreen = false; isFullscreen = false;
} }
@ -192,4 +179,18 @@ public class GraphicsBackend {
GLFWVidMode vidmode = glfwGetVideoMode(glfwGetPrimaryMonitor()); GLFWVidMode vidmode = glfwGetVideoMode(glfwGetPrimaryMonitor());
return vidmode.refreshRate(); return vidmode.refreshRate();
} }
public static boolean isMouseCaptured() {
return glfwGetInputMode(windowHandle, GLFW_CURSOR) == GLFW_CURSOR_DISABLED;
}
public static void setMouseCaptured(boolean capture) {
int mode = capture ? GLFW_CURSOR_DISABLED : GLFW_CURSOR_NORMAL;
glfwSetInputMode(windowHandle, GLFW_CURSOR, mode);
if (!capture) {
glfwSetCursorPos(windowHandle, FRAME_SIZE.x / 2.0, FRAME_SIZE.y / 2.0);
}
}
} }

View File

@ -15,7 +15,7 @@
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>. * along with this program. If not, see <https://www.gnu.org/licenses/>.
*/ */
package ru.windcorp.progressia.client.graphics.backend; package ru.windcorp.progressia.client.graphics.backend;
import glm.vec._2.i.Vec2i; import glm.vec._2.i.Vec2i;
@ -81,5 +81,13 @@ public class GraphicsInterface {
} }
GraphicsBackend.setVSyncEnabled(GraphicsBackend.isVSyncEnabled()); GraphicsBackend.setVSyncEnabled(GraphicsBackend.isVSyncEnabled());
} }
public static boolean isMouseCaptured() {
return GraphicsBackend.isMouseCaptured();
}
public static void setMouseCaptured(boolean capture) {
GraphicsBackend.setMouseCaptured(capture);
}
} }

View File

@ -15,7 +15,7 @@
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>. * along with this program. If not, see <https://www.gnu.org/licenses/>.
*/ */
package ru.windcorp.progressia.client.graphics.backend; package ru.windcorp.progressia.client.graphics.backend;
import org.lwjgl.glfw.GLFW; import org.lwjgl.glfw.GLFW;
@ -49,13 +49,7 @@ public class InputHandler {
private static final ModifiableKeyEvent THE_KEY_EVENT = new ModifiableKeyEvent(); private static final ModifiableKeyEvent THE_KEY_EVENT = new ModifiableKeyEvent();
static void handleKeyInput( static void handleKeyInput(long window, int key, int scancode, int action, int mods) {
long window,
int key,
int scancode,
int action,
int mods
) {
if (GraphicsBackend.getWindowHandle() != window) if (GraphicsBackend.getWindowHandle() != window)
return; return;
THE_KEY_EVENT.initialize(key, scancode, action, mods); THE_KEY_EVENT.initialize(key, scancode, action, mods);
@ -71,12 +65,7 @@ public class InputHandler {
} }
} }
static void handleMouseButtonInput( static void handleMouseButtonInput(long window, int key, int action, int mods) {
long window,
int key,
int action,
int mods
) {
handleKeyInput(window, key, Integer.MAX_VALUE - key, action, mods); handleKeyInput(window, key, Integer.MAX_VALUE - key, action, mods);
} }
@ -97,11 +86,7 @@ public class InputHandler {
private static final ModifiableCursorMoveEvent THE_CURSOR_MOVE_EVENT = new ModifiableCursorMoveEvent(); private static final ModifiableCursorMoveEvent THE_CURSOR_MOVE_EVENT = new ModifiableCursorMoveEvent();
static void handleMouseMoveInput( static void handleMouseMoveInput(long window, double x, double y) {
long window,
double x,
double y
) {
if (GraphicsBackend.getWindowHandle() != window) if (GraphicsBackend.getWindowHandle() != window)
return; return;
y = GraphicsInterface.getFrameHeight() - y; // Flip y axis y = GraphicsInterface.getFrameHeight() - y; // Flip y axis
@ -131,11 +116,7 @@ public class InputHandler {
private static final ModifiableWheelScrollEvent THE_WHEEL_SCROLL_EVENT = new ModifiableWheelScrollEvent(); private static final ModifiableWheelScrollEvent THE_WHEEL_SCROLL_EVENT = new ModifiableWheelScrollEvent();
static void handleWheelScroll( static void handleWheelScroll(long window, double xoffset, double yoffset) {
long window,
double xoffset,
double yoffset
) {
if (GraphicsBackend.getWindowHandle() != window) if (GraphicsBackend.getWindowHandle() != window)
return; return;
THE_WHEEL_SCROLL_EVENT.initialize(xoffset, yoffset); THE_WHEEL_SCROLL_EVENT.initialize(xoffset, yoffset);
@ -162,10 +143,7 @@ public class InputHandler {
/* /*
* NB: this is NOT a GLFW callback, the raw callback is in GraphicsBackend * NB: this is NOT a GLFW callback, the raw callback is in GraphicsBackend
*/ */
static void handleFrameResize( static void handleFrameResize(int width, int height) {
int width,
int height
) {
THE_FRAME_RESIZE_EVENT.initialize(width, height); THE_FRAME_RESIZE_EVENT.initialize(width, height);
dispatch(THE_FRAME_RESIZE_EVENT); dispatch(THE_FRAME_RESIZE_EVENT);
} }

View File

@ -15,7 +15,7 @@
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>. * along with this program. If not, see <https://www.gnu.org/licenses/>.
*/ */
package ru.windcorp.progressia.client.graphics.backend; package ru.windcorp.progressia.client.graphics.backend;
import glm.vec._2.d.Vec2d; import glm.vec._2.d.Vec2d;
@ -24,10 +24,7 @@ import gnu.trove.set.hash.TIntHashSet;
public class InputTracker { public class InputTracker {
private static final Vec2d CURSOR_POSITION = new Vec2d( private static final Vec2d CURSOR_POSITION = new Vec2d(Double.NaN, Double.NaN);
Double.NaN,
Double.NaN
);
private static final TIntSet PRESSED_KEYS = new TIntHashSet(256); private static final TIntSet PRESSED_KEYS = new TIntHashSet(256);

View File

@ -15,7 +15,7 @@
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>. * along with this program. If not, see <https://www.gnu.org/licenses/>.
*/ */
package ru.windcorp.progressia.client.graphics.backend; package ru.windcorp.progressia.client.graphics.backend;
import static org.lwjgl.opengl.GL11.*; import static org.lwjgl.opengl.GL11.*;
@ -65,10 +65,8 @@ class LWJGLInitializer {
GraphicsBackend.setWindowHandle(handle); GraphicsBackend.setWindowHandle(handle);
glfwSetInputMode(handle, GLFW_CURSOR, GLFW_CURSOR_DISABLED);
glfwMakeContextCurrent(handle); glfwMakeContextCurrent(handle);
glfwSwapInterval(0); // TODO: remove after config system is added glfwSwapInterval(0); // TODO: remove after config system is added
} }
private static void positionWindow() { private static void positionWindow() {
@ -94,16 +92,10 @@ class LWJGLInitializer {
private static void setupWindowCallbacks() { private static void setupWindowCallbacks() {
long handle = GraphicsBackend.getWindowHandle(); long handle = GraphicsBackend.getWindowHandle();
glfwSetFramebufferSizeCallback( glfwSetFramebufferSizeCallback(handle, GraphicsBackend::onFrameResized);
handle,
GraphicsBackend::onFrameResized
);
glfwSetKeyCallback(handle, InputHandler::handleKeyInput); glfwSetKeyCallback(handle, InputHandler::handleKeyInput);
glfwSetMouseButtonCallback( glfwSetMouseButtonCallback(handle, InputHandler::handleMouseButtonInput);
handle,
InputHandler::handleMouseButtonInput
);
glfwSetCursorPosCallback(handle, InputHandler::handleMouseMoveInput); glfwSetCursorPosCallback(handle, InputHandler::handleMouseMoveInput);

View File

@ -15,7 +15,7 @@
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>. * along with this program. If not, see <https://www.gnu.org/licenses/>.
*/ */
package ru.windcorp.progressia.client.graphics.backend; package ru.windcorp.progressia.client.graphics.backend;
import java.lang.ref.PhantomReference; import java.lang.ref.PhantomReference;
@ -34,19 +34,13 @@ public class OpenGLObjectTracker {
private static final ReferenceQueue<OpenGLDeletable> DELETE_QUEUE = new ReferenceQueue<>(); private static final ReferenceQueue<OpenGLDeletable> DELETE_QUEUE = new ReferenceQueue<>();
public synchronized static void register(OpenGLDeletable object, IntConsumer glDeleter) { public synchronized static void register(OpenGLDeletable object, IntConsumer glDeleter) {
GLPhantomReference<OpenGLDeletable> glRef = new GLPhantomReference<>( GLPhantomReference<OpenGLDeletable> glRef = new GLPhantomReference<>(object, DELETE_QUEUE, object.getHandle(),
object, glDeleter);
DELETE_QUEUE,
object.getHandle(),
glDeleter
);
TO_DELETE.add(glRef); TO_DELETE.add(glRef);
} }
public static void deleteAllObjects() { public static void deleteAllObjects() {
for ( for (GLPhantomReference<OpenGLDeletable> glRef : TO_DELETE) {
GLPhantomReference<OpenGLDeletable> glRef : TO_DELETE
) {
glRef.clear(); glRef.clear();
} }
} }
@ -75,20 +69,16 @@ public class OpenGLObjectTracker {
* It is possible to create a phantom reference with a {@code null} * It is possible to create a phantom reference with a {@code null}
* queue, but such a reference is completely useless: Its {@code get} * queue, but such a reference is completely useless: Its {@code get}
* method will always return {@code null} and, since it does not have a * method will always return {@code null} and, since it does not have a
* queue, * queue, it will never be enqueued.
* it will never be enqueued.
* *
* @param referent the object the new phantom reference will refer to * @param referent
* @param q the queue with which the reference is to be * the object the new phantom reference will refer to
* registered, * @param q
* or {@code null} if registration is not required * the queue with which the reference is to be registered, or
* {@code null} if registration is not required
*/ */
public GLPhantomReference( public GLPhantomReference(T referent, ReferenceQueue<? super T> q, int referentGLhandle,
T referent, IntConsumer GLDeleter) {
ReferenceQueue<? super T> q,
int referentGLhandle,
IntConsumer GLDeleter
) {
super(referent, q); super(referent, q);
this.referentGLhandle = referentGLhandle; this.referentGLhandle = referentGLhandle;
this.GLDeleter = GLDeleter; this.GLDeleter = GLDeleter;

View File

@ -15,7 +15,7 @@
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>. * along with this program. If not, see <https://www.gnu.org/licenses/>.
*/ */
package ru.windcorp.progressia.client.graphics.backend; package ru.windcorp.progressia.client.graphics.backend;
import ru.windcorp.jputil.functions.ThrowingRunnable; import ru.windcorp.jputil.functions.ThrowingRunnable;
@ -41,11 +41,7 @@ public class RenderTaskQueue {
HANDLER.invokeNow(task); HANDLER.invokeNow(task);
} }
public static <E extends Exception> void waitAndInvoke( public static <E extends Exception> void waitAndInvoke(ThrowingRunnable<E> task) throws InterruptedException, E {
ThrowingRunnable<E> task
)
throws InterruptedException,
E {
HANDLER.waitAndInvoke(task); HANDLER.waitAndInvoke(task);
} }

View File

@ -15,7 +15,7 @@
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>. * along with this program. If not, see <https://www.gnu.org/licenses/>.
*/ */
package ru.windcorp.progressia.client.graphics.backend; package ru.windcorp.progressia.client.graphics.backend;
import static org.lwjgl.glfw.GLFW.*; import static org.lwjgl.glfw.GLFW.*;

View File

@ -15,7 +15,7 @@
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>. * along with this program. If not, see <https://www.gnu.org/licenses/>.
*/ */
package ru.windcorp.progressia.client.graphics.backend; package ru.windcorp.progressia.client.graphics.backend;
import static org.lwjgl.opengl.GL15.GL_DYNAMIC_DRAW; import static org.lwjgl.opengl.GL15.GL_DYNAMIC_DRAW;
@ -23,9 +23,7 @@ import static org.lwjgl.opengl.GL15.GL_STATIC_DRAW;
import static org.lwjgl.opengl.GL15.GL_STREAM_DRAW; import static org.lwjgl.opengl.GL15.GL_STREAM_DRAW;
public enum Usage { // TODO add _COPY and _READ, pref. as another enum public enum Usage { // TODO add _COPY and _READ, pref. as another enum
STATIC(GL_STATIC_DRAW), STATIC(GL_STATIC_DRAW), DYNAMIC(GL_DYNAMIC_DRAW), STREAM(GL_STREAM_DRAW);
DYNAMIC(GL_DYNAMIC_DRAW),
STREAM(GL_STREAM_DRAW);
private final int glCode; private final int glCode;

View File

@ -15,7 +15,7 @@
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>. * along with this program. If not, see <https://www.gnu.org/licenses/>.
*/ */
package ru.windcorp.progressia.client.graphics.backend; package ru.windcorp.progressia.client.graphics.backend;
import static org.lwjgl.opengl.GL20.*; import static org.lwjgl.opengl.GL20.*;
@ -28,8 +28,7 @@ import ru.windcorp.progressia.client.graphics.backend.OpenGLObjectTracker.OpenGL
public class VertexBufferObject implements OpenGLDeletable { public class VertexBufferObject implements OpenGLDeletable {
public static enum BindTarget { public static enum BindTarget {
ARRAY(GL_ARRAY_BUFFER), ARRAY(GL_ARRAY_BUFFER), ELEMENT_ARRAY(GL_ELEMENT_ARRAY_BUFFER);
ELEMENT_ARRAY(GL_ELEMENT_ARRAY_BUFFER);
private final int glCode; private final int glCode;

View File

@ -15,7 +15,7 @@
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>. * along with this program. If not, see <https://www.gnu.org/licenses/>.
*/ */
package ru.windcorp.progressia.client.graphics.backend.shaders; package ru.windcorp.progressia.client.graphics.backend.shaders;
import ru.windcorp.progressia.common.resource.Resource; import ru.windcorp.progressia.common.resource.Resource;
@ -32,12 +32,7 @@ public class CombinedShader extends Shader {
for (int i = 1; i < resources.length; ++i) { for (int i = 1; i < resources.length; ++i) {
if (ShaderType.guessByResourceName(resources[i]) != first) { if (ShaderType.guessByResourceName(resources[i]) != first) {
throw new IllegalArgumentException( throw new IllegalArgumentException(
"Deduced shader types of " "Deduced shader types of " + resources[0] + " and " + resources[i] + " differ");
+ resources[0]
+ " and "
+ resources[i]
+ " differ"
);
} }
} }
@ -71,19 +66,8 @@ public class CombinedShader extends Shader {
if (contents.codePointAt(versionIndex) == '#') { if (contents.codePointAt(versionIndex) == '#') {
final String versionAnnotation = "#version "; final String versionAnnotation = "#version ";
if ( if (contents.regionMatches(versionIndex, versionAnnotation, 0, versionAnnotation.length())) {
contents.regionMatches( contents = contents.substring(versionIndex + versionAnnotation.length() + "120".length());
versionIndex,
versionAnnotation,
0,
versionAnnotation.length()
)
) {
contents = contents.substring(
versionIndex
+ versionAnnotation.length()
+ "120".length()
);
} }
} }

View File

@ -15,7 +15,7 @@
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>. * along with this program. If not, see <https://www.gnu.org/licenses/>.
*/ */
package ru.windcorp.progressia.client.graphics.backend.shaders; package ru.windcorp.progressia.client.graphics.backend.shaders;
import static org.lwjgl.opengl.GL11.*; import static org.lwjgl.opengl.GL11.*;

View File

@ -15,7 +15,7 @@
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>. * along with this program. If not, see <https://www.gnu.org/licenses/>.
*/ */
package ru.windcorp.progressia.client.graphics.backend.shaders; package ru.windcorp.progressia.client.graphics.backend.shaders;
import static org.lwjgl.opengl.GL11.*; import static org.lwjgl.opengl.GL11.*;
@ -57,10 +57,7 @@ public class Shader implements OpenGLDeletable {
if (resource.contains("fsh")) if (resource.contains("fsh"))
return FRAGMENT; return FRAGMENT;
throw new IllegalArgumentException( throw new IllegalArgumentException("Cannot deduce shader type from resource name \"" + resource + "\"");
"Cannot deduce shader type from resource name \"" +
resource + "\""
);
} }
} }
@ -90,10 +87,7 @@ public class Shader implements OpenGLDeletable {
} }
public Shader(String resource) { public Shader(String resource) {
this( this(ShaderType.guessByResourceName(resource), getShaderResource(resource).readAsString());
ShaderType.guessByResourceName(resource),
getShaderResource(resource).readAsString()
);
} }
@Override @Override

View File

@ -15,7 +15,7 @@
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>. * along with this program. If not, see <https://www.gnu.org/licenses/>.
*/ */
package ru.windcorp.progressia.client.graphics.backend.shaders.attributes; package ru.windcorp.progressia.client.graphics.backend.shaders.attributes;
import ru.windcorp.progressia.client.graphics.backend.shaders.Program; import ru.windcorp.progressia.client.graphics.backend.shaders.Program;

View File

@ -15,7 +15,7 @@
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>. * along with this program. If not, see <https://www.gnu.org/licenses/>.
*/ */
package ru.windcorp.progressia.client.graphics.backend.shaders.attributes; package ru.windcorp.progressia.client.graphics.backend.shaders.attributes;
import static org.lwjgl.opengl.GL11.*; import static org.lwjgl.opengl.GL11.*;
@ -51,104 +51,29 @@ public class AttributeVertexArray extends Attribute {
} }
} }
public void set( public void set(int size, boolean normalized, int stride, ByteBuffer pointer) {
int size, glVertexAttribPointer(handle, size, GL_BYTE, normalized, stride, pointer);
boolean normalized,
int stride,
ByteBuffer pointer
) {
glVertexAttribPointer(
handle,
size,
GL_BYTE,
normalized,
stride,
pointer
);
} }
public void set( public void set(int size, boolean normalized, int stride, FloatBuffer pointer) {
int size, glVertexAttribPointer(handle, size, GL_FLOAT, normalized, stride, pointer);
boolean normalized,
int stride,
FloatBuffer pointer
) {
glVertexAttribPointer(
handle,
size,
GL_FLOAT,
normalized,
stride,
pointer
);
} }
public void set( public void set(int size, boolean normalized, int stride, IntBuffer pointer) {
int size, glVertexAttribPointer(handle, size, GL_INT, normalized, stride, pointer);
boolean normalized,
int stride,
IntBuffer pointer
) {
glVertexAttribPointer(
handle,
size,
GL_INT,
normalized,
stride,
pointer
);
} }
public void set( public void set(int size, boolean normalized, int stride, ShortBuffer pointer) {
int size, glVertexAttribPointer(handle, size, GL_SHORT, normalized, stride, pointer);
boolean normalized,
int stride,
ShortBuffer pointer
) {
glVertexAttribPointer(
handle,
size,
GL_SHORT,
normalized,
stride,
pointer
);
} }
public void set( public void set(int size, int type, boolean normalized, int stride, long pointer) {
int size, glVertexAttribPointer(handle, size, type, normalized, stride, pointer);
int type,
boolean normalized,
int stride,
long pointer
) {
glVertexAttribPointer(
handle,
size,
type,
normalized,
stride,
pointer
);
} }
public void set( public void set(int size, int type, boolean normalized, int stride, VertexBufferObject vbo, long offset) {
int size,
int type,
boolean normalized,
int stride,
VertexBufferObject vbo,
long offset
) {
glBindBuffer(GL_ARRAY_BUFFER, vbo.getHandle()); glBindBuffer(GL_ARRAY_BUFFER, vbo.getHandle());
glVertexAttribPointer( glVertexAttribPointer(handle, size, type, normalized, stride, offset);
handle,
size,
type,
normalized,
stride,
offset
);
} }
} }

View File

@ -15,7 +15,7 @@
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>. * along with this program. If not, see <https://www.gnu.org/licenses/>.
*/ */
package ru.windcorp.progressia.client.graphics.backend.shaders.uniforms; package ru.windcorp.progressia.client.graphics.backend.shaders.uniforms;
import ru.windcorp.progressia.client.graphics.backend.shaders.Program; import ru.windcorp.progressia.client.graphics.backend.shaders.Program;

View File

@ -15,7 +15,7 @@
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>. * along with this program. If not, see <https://www.gnu.org/licenses/>.
*/ */
package ru.windcorp.progressia.client.graphics.backend.shaders.uniforms; package ru.windcorp.progressia.client.graphics.backend.shaders.uniforms;
import static org.lwjgl.opengl.GL20.*; import static org.lwjgl.opengl.GL20.*;

View File

@ -15,7 +15,7 @@
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>. * along with this program. If not, see <https://www.gnu.org/licenses/>.
*/ */
package ru.windcorp.progressia.client.graphics.backend.shaders.uniforms; package ru.windcorp.progressia.client.graphics.backend.shaders.uniforms;
import static org.lwjgl.opengl.GL20.*; import static org.lwjgl.opengl.GL20.*;

View File

@ -15,7 +15,7 @@
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>. * along with this program. If not, see <https://www.gnu.org/licenses/>.
*/ */
package ru.windcorp.progressia.client.graphics.backend.shaders.uniforms; package ru.windcorp.progressia.client.graphics.backend.shaders.uniforms;
import static org.lwjgl.opengl.GL20.*; import static org.lwjgl.opengl.GL20.*;

Some files were not shown because too many files have changed in this diff Show More