New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
First Person Rendering without OpenGL #2141
Merged
Cervator
merged 4 commits into
MovingBlocks:develop
from
Josharias:FirstPersonRenderingWithEntities
Feb 6, 2016
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
5ae5999
Rework hand animation to use timestamps that can be replicated to oth…
Josharias c2feadf
Fixing issues with the entity based first person camera:
Josharias c6f373f
Remove HeldItemChangedEvent, it was not serving any useful purpose.
Josharias 6f33b4b
Fix up prefabs still having "renderWithIcon"
Josharias File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
126 changes: 126 additions & 0 deletions
126
engine/src/main/java/org/terasology/logic/inventory/ItemAuthoritySystem.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,126 @@ | ||
/* | ||
* Copyright 2013 MovingBlocks | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.terasology.logic.inventory; | ||
|
||
import org.terasology.asset.Assets; | ||
import org.terasology.entitySystem.MutableComponentContainer; | ||
import org.terasology.entitySystem.entity.EntityRef; | ||
import org.terasology.entitySystem.entity.lifecycleEvents.OnActivatedComponent; | ||
import org.terasology.entitySystem.entity.lifecycleEvents.OnChangedComponent; | ||
import org.terasology.entitySystem.event.EventPriority; | ||
import org.terasology.entitySystem.event.ReceiveEvent; | ||
import org.terasology.entitySystem.systems.BaseComponentSystem; | ||
import org.terasology.entitySystem.systems.RegisterMode; | ||
import org.terasology.entitySystem.systems.RegisterSystem; | ||
import org.terasology.logic.common.ActivateEvent; | ||
import org.terasology.math.geom.Vector3f; | ||
import org.terasology.registry.In; | ||
import org.terasology.rendering.iconmesh.IconMeshFactory; | ||
import org.terasology.rendering.logic.LightComponent; | ||
import org.terasology.rendering.logic.MeshComponent; | ||
import org.terasology.utilities.random.FastRandom; | ||
import org.terasology.utilities.random.Random; | ||
import org.terasology.world.block.family.BlockFamily; | ||
import org.terasology.world.block.items.BlockItemComponent; | ||
|
||
@RegisterSystem(RegisterMode.AUTHORITY) | ||
public class ItemAuthoritySystem extends BaseComponentSystem { | ||
@In | ||
private InventoryManager inventoryManager; | ||
|
||
private static Random rand = new FastRandom(); | ||
|
||
@ReceiveEvent(components = ItemComponent.class, priority = EventPriority.PRIORITY_TRIVIAL) | ||
public void usedItem(ActivateEvent event, EntityRef item) { | ||
ItemComponent itemComp = item.getComponent(ItemComponent.class); | ||
if (itemComp.consumedOnUse) { | ||
int slot = InventoryUtils.getSlotWithItem(event.getInstigator(), item); | ||
inventoryManager.removeItem(event.getInstigator(), event.getInstigator(), slot, true, 1); | ||
} | ||
} | ||
|
||
@ReceiveEvent | ||
public void onRenderItemIconMeshActivated(OnActivatedComponent event, EntityRef item, RenderItemIconMeshComponent renderItemIconMeshComponent, ItemComponent itemComponent) { | ||
addOrUpdateItemMeshComponent(itemComponent, item); | ||
} | ||
|
||
@ReceiveEvent | ||
public void onRenderItemIconMeshChanged(OnChangedComponent event, EntityRef item, RenderItemIconMeshComponent renderItemIconMeshComponent, ItemComponent itemComponent) { | ||
addOrUpdateItemMeshComponent(itemComponent, item); | ||
} | ||
|
||
@ReceiveEvent | ||
public void onRenderItemBlockMeshActivated(OnActivatedComponent event, EntityRef item, | ||
RenderItemBlockMeshComponent renderItemBlockMeshComponent, | ||
BlockItemComponent blockItemComponent, | ||
ItemComponent itemComponent) { | ||
addOrUpdateBlockMeshComponent(blockItemComponent, item); | ||
} | ||
|
||
@ReceiveEvent | ||
public void onRenderItemBlockMeshChanged(OnChangedComponent event, EntityRef item, | ||
RenderItemBlockMeshComponent renderItemBlockMeshComponent, | ||
BlockItemComponent blockItemComponent, | ||
ItemComponent itemComponent) { | ||
addOrUpdateBlockMeshComponent(blockItemComponent, item); | ||
} | ||
|
||
public static void addOrUpdateItemMeshComponent(ItemComponent itemComponent, MutableComponentContainer entity) { | ||
if (itemComponent != null) { | ||
MeshComponent meshComponent = null; | ||
if (entity.hasComponent(MeshComponent.class)) { | ||
meshComponent = entity.getComponent(MeshComponent.class); | ||
} else { | ||
meshComponent = new MeshComponent(); | ||
} | ||
meshComponent.material = Assets.getMaterial("engine:droppedItem").get(); | ||
if (itemComponent.icon != null) { | ||
meshComponent.mesh = IconMeshFactory.getIconMesh(itemComponent.icon); | ||
} | ||
entity.addOrSaveComponent(meshComponent); | ||
} | ||
} | ||
|
||
public static void addOrUpdateBlockMeshComponent(BlockItemComponent blockItemComponent, MutableComponentContainer entity) { | ||
if (blockItemComponent != null) { | ||
MeshComponent meshComponent = null; | ||
if (entity.hasComponent(MeshComponent.class)) { | ||
meshComponent = entity.getComponent(MeshComponent.class); | ||
} else { | ||
meshComponent = new MeshComponent(); | ||
} | ||
BlockFamily blockFamily = blockItemComponent.blockFamily; | ||
|
||
if (blockFamily == null) { | ||
return; | ||
} | ||
|
||
meshComponent.mesh = blockFamily.getArchetypeBlock().getMeshGenerator().getStandaloneMesh(); | ||
meshComponent.material = Assets.getMaterial("engine:terrain").get(); | ||
|
||
if (blockFamily.getArchetypeBlock().getLuminance() > 0 && !entity.hasComponent(LightComponent.class)) { | ||
LightComponent lightComponent = entity.addComponent(new LightComponent()); | ||
|
||
Vector3f randColor = new Vector3f(rand.nextFloat(), rand.nextFloat(), rand.nextFloat()); | ||
lightComponent.lightColorDiffuse.set(randColor); | ||
lightComponent.lightColorAmbient.set(randColor); | ||
} | ||
|
||
entity.addOrSaveComponent(meshComponent); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This prevents prefabs that do not specify a cooldown to get a better value than "machine gun"