-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added semantic timer events again and separate event types
- Loading branch information
Showing
8 changed files
with
222 additions
and
115 deletions.
There are no files selected for viewing
28 changes: 28 additions & 0 deletions
28
engine/src/main/java/org/terasology/world/time/OnDawnEvent.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,28 @@ | ||
/* | ||
* 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.world.time; | ||
|
||
/** | ||
* Sent to a world on dawn (beginning of a new day) | ||
* | ||
* @author Immortius | ||
*/ | ||
public class OnDawnEvent extends TimeEventBase { | ||
|
||
public OnDawnEvent(long worldTimeMS) { | ||
super(worldTimeMS); | ||
} | ||
} |
28 changes: 28 additions & 0 deletions
28
engine/src/main/java/org/terasology/world/time/OnDuskEvent.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,28 @@ | ||
/* | ||
* 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.world.time; | ||
|
||
/** | ||
* Sent to the world on dusk (half way through the day, when the sun sets) | ||
* | ||
* @author Immortius | ||
*/ | ||
public class OnDuskEvent extends TimeEventBase { | ||
|
||
public OnDuskEvent(long worldTimeMS) { | ||
super(worldTimeMS); | ||
} | ||
} |
28 changes: 28 additions & 0 deletions
28
engine/src/main/java/org/terasology/world/time/OnMiddayEvent.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,28 @@ | ||
/* | ||
* 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.world.time; | ||
|
||
/** | ||
* Sent to a world in the middle of daytime | ||
* | ||
* @author Immortius | ||
*/ | ||
public class OnMiddayEvent extends TimeEventBase { | ||
|
||
public OnMiddayEvent(long worldTimeMS) { | ||
super(worldTimeMS); | ||
} | ||
} |
28 changes: 28 additions & 0 deletions
28
engine/src/main/java/org/terasology/world/time/OnMidnightEvent.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,28 @@ | ||
/* | ||
* 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.world.time; | ||
|
||
/** | ||
* Sent to a world at the middle of the night | ||
* | ||
* @author Immortius | ||
*/ | ||
public class OnMidnightEvent extends TimeEventBase { | ||
|
||
public OnMidnightEvent(long worldTimeMS) { | ||
super(worldTimeMS); | ||
} | ||
} |
64 changes: 64 additions & 0 deletions
64
engine/src/main/java/org/terasology/world/time/TimeEventBase.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,64 @@ | ||
/* | ||
* Copyright 2014 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.world.time; | ||
|
||
import org.terasology.entitySystem.event.Event; | ||
|
||
import com.google.common.math.LongMath; | ||
|
||
/** | ||
* A base class for different timer events | ||
* @author Martin Steiger | ||
*/ | ||
public abstract class TimeEventBase implements Event { | ||
|
||
private long worldTimeMS; | ||
private long timeInDay; | ||
|
||
public TimeEventBase(long worldTimeMS) { | ||
this.worldTimeMS = worldTimeMS; | ||
this.timeInDay = LongMath.mod(worldTimeMS, WorldTime.DAY_LENGTH); | ||
} | ||
|
||
/** | ||
* @return the time of day as a fraction | ||
*/ | ||
public float getDayTime() { | ||
return timeInDay / (float) WorldTime.DAY_LENGTH; | ||
} | ||
|
||
/** | ||
* @return the time of day in milli secs | ||
*/ | ||
public long getDayTimeInMs() { | ||
return timeInDay; | ||
} | ||
|
||
/** | ||
* @return the world time in days | ||
*/ | ||
public float getWorldTime() { | ||
return worldTimeMS / (float) WorldTime.DAY_LENGTH; | ||
} | ||
|
||
/** | ||
* @return the world time in milli secs | ||
*/ | ||
public long getWorldTimeInMs() { | ||
return worldTimeMS; | ||
} | ||
} |
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
Oops, something went wrong.