Skip to content

Commit

Permalink
[MRG] Overhaul atmos and introduce world's subsystems
Browse files Browse the repository at this point in the history
Base changes for new atmos locales logic, which supports z-levels, and produces more accurate locales. Also atmos is mostly prepared for moving to separate thread. For this purpose subsystems are introduced.

Also some minor bugs are fixed.

At the GameLogic side opacity and airtightness attributes are added to Object. Airtightness is used for locales creating and opacity will be used later.

PR #74
  • Loading branch information
Insineer authored Oct 30, 2019
2 parents 08d87f1 + 81de632 commit 94c95d9
Show file tree
Hide file tree
Showing 47 changed files with 700 additions and 551 deletions.
22 changes: 12 additions & 10 deletions GameLogic/Engine/Geometry.py
Original file line number Diff line number Diff line change
Expand Up @@ -209,16 +209,18 @@ class Direction(eDirection):
Direction enumeration
8 existing world directions, Center and None
"""
NONE = eDirection.NONE
SOUTH = eDirection.SOUTH
WEST = eDirection.WEST
NORTH = eDirection.NORTH
EAST = eDirection.EAST
SOUTH_WEST = eDirection.SOUTH_WEST
NORTH_WEST = eDirection.NORTH_WEST
NORTH_EAST = eDirection.NORTH_EAST
SOUTH_EAST = eDirection.SOUTH_EAST
CENTER = eDirection.CENTER
NONE = eDirection.NONE
SOUTH = eDirection.SOUTH
WEST = eDirection.WEST
NORTH = eDirection.NORTH
EAST = eDirection.EAST
SOUTH_WEST = eDirection.SOUTH_WEST
NORTH_WEST = eDirection.NORTH_WEST
NORTH_EAST = eDirection.NORTH_EAST
SOUTH_EAST = eDirection.SOUTH_EAST
TOP = eDirection.TOP
BOTTOM = eDirection.BOTTOM
CENTER = eDirection.CENTER


def DirectionToVect(dir: Direction) -> Vector2D:
Expand Down
46 changes: 21 additions & 25 deletions GameLogic/Engine/World.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from Engine_Geometry import *

import Engine.Server
from Engine.Geometry import Vector, Vector2D, Direction, DirectionSet, NextDirection
from Engine.Geometry import Vector, Vector2D, Direction, DirectionSet, NextDirection, DirectionSetFractional

from datetime import timedelta
from typing import Callable
Expand Down Expand Up @@ -174,6 +174,12 @@ class Object(eObject):
then no one dense object can walk in this tile from any direction
- any composite direction is breaks down to main directions
opacity: DirectionSetFractional
object opacity by directions. Used by lighting subsystem
aitrtightness: DirectionSetFractional
object aitrtightness by directions. Used by atmos subsystem
invisibility: int
invisibility flags of object (each bit is different type of invisibility)
Expand All @@ -193,16 +199,6 @@ class Object(eObject):
should the object be drawn as ceiling
if true, then object will not be drawn on its z-level, but will be drawn when camera is above
isWall: bool
True if object is wall. Used for atmosphere subsystem
Note: don't use it! Will be remove in next builds.
isFloor: bool
True if object is floor. Used for atmosphere subsystem
Note: don't use it! Will be remove in next builds.
Methods
-------
Expand Down Expand Up @@ -375,6 +371,20 @@ def solidity(self) -> DirectionSet:
def solidity(self, value: DirectionSet):
super(Object, self.__class__).solidity.fset(self, value._impl)

@property
def opacity(self) -> DirectionSetFractional:
return DirectionSetFractional(super().opacity)
@opacity.setter
def opacity(self, value: DirectionSetFractional):
super(Object, self.__class__).opacity.fset(self, value._impl)

@property
def airtightness(self) -> DirectionSetFractional:
return DirectionSetFractional(super().airtightness)
@airtightness.setter
def airtightness(self, value: DirectionSetFractional):
super(Object, self.__class__).airtightness.fset(self, value._impl)

@property
def invisibility(self) -> int:
return super().invisibility
Expand Down Expand Up @@ -424,20 +434,6 @@ def drawAtTop(self) -> bool:
def drawAtTop(self, value: bool):
super(Object, self.__class__).drawAtTop.fset(self, value)

@property
def isFloor(self) -> bool:
return super().isFloor
@isFloor.setter
def isFloor(self, value: bool):
super(Object, self.__class__).isFloor.fset(self, value)

@property
def isWall(self) -> bool:
return super().isWall
@isWall.setter
def isWall(self, value: bool):
super(Object, self.__class__).isWall.fset(self, value)

def Update(self, timeElapsed: timedelta):
pass

Expand Down
5 changes: 4 additions & 1 deletion GameLogic/Objects/Turfs/Airlock.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from Engine.Geometry import Direction, DirectionSet
from Engine.Geometry import Direction, DirectionSet, DirectionSetFractional
from Objects.Turf import Turf

class Airlock(Turf):
Expand All @@ -13,6 +13,9 @@ def __init__(self):

self.solidity = self.__closedSolidity

self.opacity = DirectionSetFractional([(Direction.CENTER, 0)])
self.airtightness = DirectionSetFractional([(Direction.CENTER, 0)])

self.opened = False
self.locked = False

Expand Down
4 changes: 4 additions & 0 deletions GameLogic/Objects/Turfs/Ceiling.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from Engine.Geometry import Direction, DirectionSet, DirectionSetFractional
from Objects.Turf import Turf

class Ceiling(Turf):
Expand All @@ -8,3 +9,6 @@ def __init__(self):
super().__init__()
self.drawAtTop = True
self.layer = 10
self.solidity = DirectionSet([Direction.TOP])
self.opacity = DirectionSetFractional([(Direction.TOP, 0)])
self.airtightness = DirectionSetFractional([(Direction.TOP, 0)])
5 changes: 4 additions & 1 deletion GameLogic/Objects/Turfs/Floor.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from Engine.Geometry import Direction, DirectionSet, DirectionSetFractional
from Objects.Turf import Turf

class Floor(Turf):
Expand All @@ -6,5 +7,7 @@ class Floor(Turf):

def __init__(self):
super().__init__()
self.isFloor = True
self.layer = 15
self.solidity = DirectionSet([Direction.BOTTOM])
self.opacity = DirectionSetFractional([(Direction.BOTTOM, 0)])
self.airtightness = DirectionSetFractional([(Direction.BOTTOM, 0)])
5 changes: 3 additions & 2 deletions GameLogic/Objects/Turfs/Wall.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from Engine.Geometry import Direction, DirectionSet
from Engine.Geometry import Direction, DirectionSet, DirectionSetFractional
from Objects.Turf import Turf

class Wall(Turf):
Expand All @@ -7,5 +7,6 @@ class Wall(Turf):

def __init__(self):
super().__init__()
self.isWall = True
self.solidity = DirectionSet([Direction.CENTER])
self.opacity = DirectionSetFractional([(Direction.CENTER, 0)])
self.airtightness = DirectionSetFractional([(Direction.CENTER, 0)])
2 changes: 1 addition & 1 deletion OSS13 Client/Sources/Graphics/TileGrid/Object.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ void Object::ResetShiftingState() {
}

void Object::ReverseShifting(uf::Direction direction) {
uf::vec2i directionVect = uf::DirectionToVect(direction);
uf::vec2i directionVect = uf::DirectionToVect(direction).xy();
if (directionVect.x) moveIntent.x = 0, moveIntentApproved.x = 0;
if (directionVect.y) moveIntent.y = 0, moveIntentApproved.y = 0;
shift -= directionVect;
Expand Down
6 changes: 3 additions & 3 deletions OSS13 Client/Sources/Graphics/TileGrid/TileGrid.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -434,7 +434,7 @@ void TileGrid::SetMoveIntentObject(uint id, uf::Direction direction) {
auto iter = objects.find(id);
if (objects.find(id) != objects.end()) {
Object *obj = iter->second.get();
uf::vec2i dir = uf::DirectionToVect(direction);
uf::vec2i dir = uf::DirectionToVect(direction).xy();
obj->SetMoveIntent(dir, true);
return;
}
Expand All @@ -445,7 +445,7 @@ void TileGrid::MoveObject(uint id, uf::Direction direction, float speed) {
auto iter = objects.find(id);
if (objects.find(id) != objects.end()) {
Object *obj = iter->second.get();
uf::vec2i dir = uf::DirectionToVect(direction);
uf::vec2i dir = uf::DirectionToVect(direction).xy();

Tile *lastTile = obj->GetTile();
if (!lastTile) {
Expand Down Expand Up @@ -569,7 +569,7 @@ void TileGrid::UpdateOverlay(std::vector<network::protocol::OverlayInfo> &overla
overlayToggled = true;
auto tileOverlayInfo = overlayInfo.begin();
for (auto &tile : blocks.Items()) {
EXPECT(tileOverlayInfo != overlayInfo.end());
//EXPECT(tileOverlayInfo != overlayInfo.end()); TODO: fix overlays, for now they are shit :(
if (tile) {
tile->SetOverlay(tileOverlayInfo->text);
tileOverlayInfo++;
Expand Down
9 changes: 9 additions & 0 deletions OSS13 Server/Include/World/ISubsystem.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#pragma once

#include <chrono>

#include <Shared/IFaces/IFace.h>

struct ISubsystem : IFace {
virtual void Update(std::chrono::microseconds timeElapsed) = 0;
};
27 changes: 27 additions & 0 deletions OSS13 Server/Include/World/ITile.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#pragma once

#include <chrono>
#include <list>

#include <Shared/IFaces/IFace.h>
#include <Shared/Geometry/DirectionSet.h>

class Object;
class Map;

struct ITile : public IFace {
virtual void Update(std::chrono::microseconds timeElapsed) = 0;

virtual bool MoveTo(Object *) = 0;
virtual void PlaceTo(Object *) = 0;
virtual bool RemoveObject(Object *obj) = 0;

virtual const std::list<Object *> &Content() const = 0;

virtual uf::vec3i GetPos() const = 0;
virtual ITile *StepTo(uf::Direction direction) const = 0;
virtual Map *GetMap() const = 0;

virtual bool IsDense(uf::DirectionSet directions) const = 0;
virtual Object *GetDenseObject(uf::DirectionSet directions) const = 0;
};
22 changes: 22 additions & 0 deletions OSS13 Server/Include/World/Subsystems/IAtmos.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#pragma once

#include <Shared/IFaces/IHasRepeatableID.h>
#include <Shared/Geometry/DirectionSet.h>

#include <World/ISubsystem.h>

namespace subsystem {

namespace atmos {

struct ILocale : public IFace, public IHasRepeatableID {

};

} // namespace atmos

struct IAtmos : public ISubsystem {

};

} // namespace subsystem
20 changes: 20 additions & 0 deletions OSS13 Server/Include/World/Subsystems/IAtmosTile.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#pragma once

#include <World/ITile.h>
#include <World/Subsystems/IAtmos.h>

namespace subsystem {
namespace atmos {

struct IAtmosTile : public ITile {
virtual bool SynchronizeAtmos() = 0;

virtual ILocale *GetLocale() = 0;
virtual void SetLocale(ILocale *locale) = 0;

virtual uf::DirectionSetFractional GetAirtightness() const = 0;
virtual float GetAirtightnessTo(uf::Direction direction) const = 0;
};

} // namespace atmos
} // namespace subsystem
22 changes: 13 additions & 9 deletions OSS13 Server/OSS13 Server.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -147,10 +147,9 @@
<ClCompile Include="Sources\ScriptEngine\ScriptEngine.cpp" />
<ClCompile Include="Sources\Server.cpp" />
<ClCompile Include="Sources\VerbsHolder.cpp" />
<ClCompile Include="Sources\World\Atmos\Atmos.cpp" />
<ClCompile Include="Sources\World\Atmos\AtmosCameraOverlay.cpp" />
<ClCompile Include="Sources\World\Atmos\AtmosOverlayWindowSink.cpp" />
<ClCompile Include="Sources\World\Atmos\Locale.cpp" />
<ClCompile Include="Sources\World\Subsystems\Atmos\Atmos.cpp" />
<ClCompile Include="Sources\World\Subsystems\Atmos\AtmosCameraOverlay.cpp" />
<ClCompile Include="Sources\World\Subsystems\Atmos\AtmosOverlayWindowSink.cpp" />
<ClCompile Include="Sources\World\Camera\Camera.cpp" />
<ClCompile Include="Sources\World\Map.cpp" />
<ClCompile Include="Sources\World\Objects\Component.cpp" />
Expand All @@ -159,6 +158,7 @@
<ClCompile Include="Sources\World\Objects\CreateObject.cpp" />
<ClCompile Include="Sources\World\Objects\Object.cpp" />
<ClCompile Include="Sources\World\Objects\ObjectHolder.cpp" />
<ClCompile Include="Sources\World\Subsystems\Atmos\AtmosTile.cpp" />
<ClCompile Include="Sources\World\Tile.cpp" />
<ClCompile Include="Sources\World\World.cpp" />
</ItemGroup>
Expand All @@ -167,6 +167,10 @@
<ClInclude Include="Include\IScriptEngine.h" />
<ClInclude Include="Include\IServer.h" />
<ClInclude Include="Include\IVerbsHolder.h" />
<ClInclude Include="Include\World\ISubsystem.h" />
<ClInclude Include="Include\World\ITile.h" />
<ClInclude Include="Include\World\Subsystems\IAtmosTile.h" />
<ClInclude Include="Include\World\Subsystems\IAtmos.h" />
<ClInclude Include="Sources\Chat.h" />
<ClInclude Include="Sources\ClientUI\WelcomeWindowSink.h" />
<ClInclude Include="Sources\Database\UsersDB.hpp" />
Expand All @@ -186,11 +190,11 @@
<ClInclude Include="Sources\ScriptEngine\Trampoline\PyObject.h" />
<ClInclude Include="Sources\Server.hpp" />
<ClInclude Include="Sources\VerbsHolder.h" />
<ClInclude Include="Sources\World\Atmos\Atmos.hpp" />
<ClInclude Include="Sources\World\Atmos\AtmosCameraOverlay.h" />
<ClInclude Include="Sources\World\Atmos\AtmosOverlayWindowSink.h" />
<ClInclude Include="Sources\World\Atmos\Gases.hpp" />
<ClInclude Include="Sources\World\Atmos\Locale.hpp" />
<ClInclude Include="Sources\World\Subsystems\Atmos\Atmos.h" />
<ClInclude Include="Sources\World\Subsystems\Atmos\AtmosCameraOverlay.h" />
<ClInclude Include="Sources\World\Subsystems\Atmos\AtmosOverlayWindowSink.h" />
<ClInclude Include="Sources\World\Subsystems\Atmos\AtmosTile.h" />
<ClInclude Include="Sources\World\Subsystems\Atmos\Gases.hpp" />
<ClInclude Include="Sources\World\Block.hpp" />
<ClInclude Include="Sources\World\Camera\Camera.hpp" />
<ClInclude Include="Sources\World\Camera\ICameraOverlay.h" />
Expand Down
Loading

0 comments on commit 94c95d9

Please sign in to comment.