Skip to content

Commit

Permalink
CsCamera initial (#531)
Browse files Browse the repository at this point in the history
* CsCamera initial

* address code review
  • Loading branch information
thokkat authored Nov 13, 2023
1 parent de35246 commit f04671a
Show file tree
Hide file tree
Showing 12 changed files with 298 additions and 33 deletions.
12 changes: 11 additions & 1 deletion game/camera.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -624,6 +624,12 @@ void Camera::calcControlPoints(float dtF) {
rotBest = Vec3();
//spin.y += def.bestAzimuth;
}
auto world = Gothic::inst().world();
if(world!=nullptr && world->currentCs()!=nullptr) {
range = 0;
rotOffset = Vec3();
rotOffsetDef = Vec3();
}

followAng(src.spin, dst.spin+rotBest, dtF);
if(!isMarvin())
Expand All @@ -645,7 +651,7 @@ void Camera::calcControlPoints(float dtF) {
followCamera(cameraPos,src.target,dtF);

origin = cameraPos - dir*range;
if(camMarvinMod==M_Free) {
if(camMarvinMod==M_Free || (world!=nullptr && world->currentCs()!=nullptr)) {
return;
}

Expand Down Expand Up @@ -829,6 +835,10 @@ PointF Camera::destSpin() const {
return PointF(dst.spin.x,dst.spin.y);
}

Vec3 Camera::destPosition() const {
return dst.target;
}

Matrix4x4 Camera::viewProj() const {
Matrix4x4 ret=projective();
ret.mul(view());
Expand Down
2 changes: 2 additions & 0 deletions game/camera.h
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,8 @@ class Camera final {
Tempest::PointF spin() const;
Tempest::PointF destSpin() const;

Tempest::Vec3 destPosition() const;

void setSpin(const Tempest::PointF& p);
void setDestSpin(const Tempest::PointF& p);

Expand Down
6 changes: 6 additions & 0 deletions game/game/playercontrol.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@ void PlayerControl::onKeyPressed(KeyCodec::Action a, Tempest::KeyEvent::KeyType
auto ws = pl ? pl->weaponState() : WeaponState::NoWeapon;
uint8_t slot = pl ? pl->inventory().currentSpellSlot() : Item::NSLOT;

if(w!=nullptr && w->currentCs()!=nullptr)
return;

handleMovementAction(KeyCodec::ActionMapping{a,mapping}, true);

if(pl!=nullptr && pl->interactive()!=nullptr && c!=nullptr && !c->isFree()) {
Expand Down Expand Up @@ -514,6 +517,9 @@ bool PlayerControl::tickMove(uint64_t dt) {
Npc* pl = w->player();
auto camera = Gothic::inst().camera();

if(w->currentCs()!=nullptr)
return true;

if(camera!=nullptr && (camera->isFree() || pl==nullptr)) {
rotMouse = 0;
if(ctrl[KeyCodec::Left] || (ctrl[KeyCodec::RotateL] && ctrl[KeyCodec::Jump])) {
Expand Down
65 changes: 36 additions & 29 deletions game/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,8 @@ void MainWindow::processMouse(MouseEvent& event, bool enable) {
}

void MainWindow::tickMouse() {
if(dialogs.hasContent() || Gothic::inst().isPause()) {
auto world = Gothic::inst().world();
if(dialogs.hasContent() || Gothic::inst().isPause() || (world!=nullptr && world->currentCs()!=nullptr)) {
dMouse = Point();
return;
}
Expand All @@ -336,7 +337,8 @@ void MainWindow::tickMouse() {
if(camLookaroundInverse)
dpScaled.y *= -1.f;

if(auto camera = Gothic::inst().camera())
auto camera = Gothic::inst().camera();
if(camera!=nullptr)
camera->onRotateMouse(PointF(dpScaled.y,-dpScaled.x));
if(!inventory.isActive()) {
player.onRotateMouse (-dpScaled.x);
Expand Down Expand Up @@ -531,7 +533,7 @@ void MainWindow::paintFocus(Painter& p, const Focus& focus, const Matrix4x4& vp)

auto world = Gothic::inst().world();
auto pl = world==nullptr ? nullptr : world->player();
if(pl==nullptr)
if(pl==nullptr || world->currentCs()!=nullptr)
return;

auto pos = focus.displayPosition();
Expand Down Expand Up @@ -851,9 +853,10 @@ void MainWindow::updateAnimation(uint64_t dt) {
}

void MainWindow::tickCamera(uint64_t dt) {
auto world = Gothic::inst().world();
auto pcamera = Gothic::inst().camera();
auto pl = Gothic::inst().player();
if(pcamera==nullptr || pl==nullptr)
if(world==nullptr || pcamera==nullptr || pl==nullptr)
return;

auto& camera = *pcamera;
Expand All @@ -863,36 +866,38 @@ void MainWindow::tickCamera(uint64_t dt) {
ws==WeaponState::W2H);
auto pos = pl->cameraBone(camera.isFirstPerson());

const bool fs = SystemApi::isFullscreen(hwnd());
if(!fs && mouseP[Event::ButtonLeft]) {
camera.setSpin(camera.destSpin());
camera.setDestPosition(pos);
}
else if(dialogs.isActive() && !dialogs.isMobsiDialog()) {
dialogs.dialogCamera(camera);
}
else if(inventory.isActive()) {
camera.setDestPosition(pos);
}
else if(player.focus().npc!=nullptr && meleeFocus) {
auto spin = camera.destSpin();
spin.y = pl->rotation();
camera.setDestSpin(spin);
camera.setDestPosition(pos);
}
else {
auto spin = camera.destSpin();
if(pl->interactive()==nullptr && !pl->isDown())
if(world->currentCs()==nullptr) {
const bool fs = SystemApi::isFullscreen(hwnd());
if(!fs && mouseP[Event::ButtonLeft]) {
camera.setSpin(camera.destSpin());
camera.setDestPosition(pos);
}
else if(dialogs.isActive() && !dialogs.isMobsiDialog()) {
dialogs.dialogCamera(camera);
}
else if(inventory.isActive()) {
camera.setDestPosition(pos);
}
else if(player.focus().npc!=nullptr && meleeFocus) {
auto spin = camera.destSpin();
spin.y = pl->rotation();
if(pl->isDive() && !camera.isMarvin())
spin.x = -pl->rotationY();
camera.setDestSpin(spin);
camera.setDestPosition(pos);
camera.setDestSpin(spin);
camera.setDestPosition(pos);
}
else {
auto spin = camera.destSpin();
if(pl->interactive()==nullptr && !pl->isDown())
spin.y = pl->rotation();
if(pl->isDive() && !camera.isMarvin())
spin.x = -pl->rotationY();
camera.setDestSpin(spin);
camera.setDestPosition(pos);
}
}

if(dt==0)
return;
if(camera.isToggleEnabled())
if(camera.isToggleEnabled() && world->currentCs()==nullptr)
camera.setMode(solveCameraMode());
camera.tick(dt);
}
Expand Down Expand Up @@ -977,6 +982,8 @@ void MainWindow::saveGame(std::string_view slot, std::string_view name) {

if(dialogs.isActive())
return;
if(auto w = Gothic::inst().world(); w!=nullptr && w->currentCs()!=nullptr)
return;

Gothic::inst().startSave(std::move(textureCast(tex)),[slot=std::string(slot),name=std::string(name),pm](std::unique_ptr<GameSession>&& game){
if(!game)
Expand Down
10 changes: 10 additions & 0 deletions game/marvin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

#include "utils/string_frm.h"
#include "world/objects/npc.h"
#include "world/triggers/abstracttrigger.h"
#include "camera.h"
#include "gothic.h"

Expand Down Expand Up @@ -125,6 +126,7 @@ Marvin::Marvin() {
{"toggle camdebug", C_ToggleCamDebug},
{"toggle camera", C_ToggleCamera},
{"toggle inertiatarget", C_ToggleInertia},
{"ztoggle timedemo", C_ZToggleTimeDemo},
{"insert %c", C_Insert},

{"toggle gi", C_ToggleGI},
Expand Down Expand Up @@ -330,6 +332,14 @@ bool Marvin::exec(std::string_view v) {
c->setInertiaTargetEnable(!c->isInertiaTargetEnabled());
return true;
}
case C_ZToggleTimeDemo: {
World* world = Gothic::inst().world();
if(world==nullptr)
return false;
const TriggerEvent evt("TIMEDEMO","",world->tickCount(),TriggerEvent::T_Trigger);
world->triggerEvent(evt);
return true;
}
case C_ToggleDesktop: {
Gothic::inst().toggleDesktop();
return true;
Expand Down
1 change: 1 addition & 0 deletions game/marvin.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ class Marvin {
C_ToggleCamDebug,
C_ToggleCamera,
C_ToggleInertia,
C_ZToggleTimeDemo,

C_AiGoTo,
C_GoToPos,
Expand Down
Loading

0 comments on commit f04671a

Please sign in to comment.