forked from Kolyah35/minecraft-pe-0.6.1
pragma once everywhere
This commit is contained in:
@@ -1,110 +1,108 @@
|
||||
#ifndef NET_MINECRAFT_CLIENT_PLAYER__LocalPlayer_H__
|
||||
#define NET_MINECRAFT_CLIENT_PLAYER__LocalPlayer_H__
|
||||
|
||||
//package net.minecraft.client.player;
|
||||
|
||||
#include "input/IMoveInput.h"
|
||||
#include "../../util/SmoothFloat.h"
|
||||
#include "../../world/entity/player/Player.h"
|
||||
|
||||
class MinecraftClient;
|
||||
class Stat;
|
||||
class CompoundTag;
|
||||
|
||||
class LocalPlayer: public Player
|
||||
{
|
||||
typedef Player super;
|
||||
public:
|
||||
LocalPlayer(MinecraftClient& minecraft, Level* level, const std::string& username, int dimension, bool isCreative);
|
||||
~LocalPlayer();
|
||||
|
||||
void _init();
|
||||
virtual void reset();
|
||||
|
||||
void tick();
|
||||
void move(float xa, float ya, float za);
|
||||
|
||||
void aiStep();
|
||||
void updateAi();
|
||||
|
||||
void setKey(int eventKey, bool eventKeyState);
|
||||
void releaseAllKeys();
|
||||
|
||||
void addAdditonalSaveData(CompoundTag* entityTag);
|
||||
void readAdditionalSaveData(CompoundTag* entityTag);
|
||||
|
||||
void closeContainer();
|
||||
|
||||
void drop(ItemInstance* item, bool randomly);
|
||||
void take(Entity* e, int orgCount);
|
||||
|
||||
void startCrafting(int x, int y, int z, int tableSize);
|
||||
void startStonecutting(int x, int y, int z);
|
||||
|
||||
void openContainer(ChestTileEntity* container);
|
||||
void openFurnace(FurnaceTileEntity* e);
|
||||
|
||||
bool isSneaking();
|
||||
|
||||
void actuallyHurt(int dmg);
|
||||
void hurtTo(int newHealth);
|
||||
void die(Entity* source);
|
||||
|
||||
void respawn();
|
||||
|
||||
void animateRespawn() {}
|
||||
float getFieldOfViewModifier();
|
||||
void chat(const std::string& message) {}
|
||||
void displayClientMessage(const std::string& messageId);
|
||||
|
||||
void awardStat(Stat* stat, int count) {
|
||||
//minecraft->stats.award(stat, count);
|
||||
//minecraft->achievementPopup.popup("Achievement get!", stat.name);
|
||||
}
|
||||
void causeFallDamage( float distance );
|
||||
|
||||
virtual int startSleepInBed(int x, int y, int z);
|
||||
virtual void stopSleepInBed(bool forcefulWakeUp, bool updateLevelList, bool saveRespawnPoint);
|
||||
|
||||
void swing();
|
||||
virtual void openTextEdit( TileEntity* tileEntity );
|
||||
virtual float getWalkingSpeedModifier();
|
||||
private:
|
||||
void calculateFlight(float xa, float ya, float za);
|
||||
bool isSolidTile(int x, int y, int z);
|
||||
void updateArmorTypeHash();
|
||||
public:
|
||||
IMoveInput* input = nullptr;
|
||||
bool autoJumpEnabled = true;
|
||||
protected:
|
||||
MinecraftClient& minecraft;
|
||||
int jumpTriggerTime;
|
||||
int ascendTriggerTime;
|
||||
int descendTriggerTime;
|
||||
bool ascending, descending;
|
||||
private:
|
||||
// local player fly
|
||||
// -----------------------
|
||||
float flyX, flyY, flyZ;
|
||||
|
||||
// smooth camera settings
|
||||
SmoothFloat smoothFlyX;
|
||||
SmoothFloat smoothFlyY;
|
||||
SmoothFloat smoothFlyZ;
|
||||
|
||||
int autoJumpTime;
|
||||
|
||||
int sentInventoryItemId = -1;
|
||||
int sentInventoryItemData = -1;
|
||||
|
||||
int armorTypeHash = 0;
|
||||
|
||||
// sprinting
|
||||
bool sprinting = false;
|
||||
int sprintDoubleTapTimer = 0;
|
||||
bool prevForwardHeld = false;
|
||||
public:
|
||||
void setSprinting(bool sprint) { sprinting = sprint; }
|
||||
};
|
||||
|
||||
#endif /*NET_MINECRAFT_CLIENT_PLAYER__LocalPlayer_H__*/
|
||||
#pragma once
|
||||
|
||||
//package net.minecraft.client.player;
|
||||
|
||||
#include "input/IMoveInput.h"
|
||||
#include "../../util/SmoothFloat.h"
|
||||
#include "../../world/entity/player/Player.h"
|
||||
|
||||
class MinecraftClient;
|
||||
class Stat;
|
||||
class CompoundTag;
|
||||
|
||||
class LocalPlayer: public Player
|
||||
{
|
||||
typedef Player super;
|
||||
public:
|
||||
LocalPlayer(MinecraftClient& minecraft, Level* level, const std::string& username, int dimension, bool isCreative);
|
||||
~LocalPlayer();
|
||||
|
||||
void _init();
|
||||
virtual void reset();
|
||||
|
||||
void tick();
|
||||
void move(float xa, float ya, float za);
|
||||
|
||||
void aiStep();
|
||||
void updateAi();
|
||||
|
||||
void setKey(int eventKey, bool eventKeyState);
|
||||
void releaseAllKeys();
|
||||
|
||||
void addAdditonalSaveData(CompoundTag* entityTag);
|
||||
void readAdditionalSaveData(CompoundTag* entityTag);
|
||||
|
||||
void closeContainer();
|
||||
|
||||
void drop(ItemInstance* item, bool randomly);
|
||||
void take(Entity* e, int orgCount);
|
||||
|
||||
void startCrafting(int x, int y, int z, int tableSize);
|
||||
void startStonecutting(int x, int y, int z);
|
||||
|
||||
void openContainer(ChestTileEntity* container);
|
||||
void openFurnace(FurnaceTileEntity* e);
|
||||
|
||||
bool isSneaking();
|
||||
|
||||
void actuallyHurt(int dmg);
|
||||
void hurtTo(int newHealth);
|
||||
void die(Entity* source);
|
||||
|
||||
void respawn();
|
||||
|
||||
void animateRespawn() {}
|
||||
float getFieldOfViewModifier();
|
||||
void chat(const std::string& message) {}
|
||||
void displayClientMessage(const std::string& messageId);
|
||||
|
||||
void awardStat(Stat* stat, int count) {
|
||||
//minecraft->stats.award(stat, count);
|
||||
//minecraft->achievementPopup.popup("Achievement get!", stat.name);
|
||||
}
|
||||
void causeFallDamage( float distance );
|
||||
|
||||
virtual int startSleepInBed(int x, int y, int z);
|
||||
virtual void stopSleepInBed(bool forcefulWakeUp, bool updateLevelList, bool saveRespawnPoint);
|
||||
|
||||
void swing();
|
||||
virtual void openTextEdit( TileEntity* tileEntity );
|
||||
virtual float getWalkingSpeedModifier();
|
||||
private:
|
||||
void calculateFlight(float xa, float ya, float za);
|
||||
bool isSolidTile(int x, int y, int z);
|
||||
void updateArmorTypeHash();
|
||||
public:
|
||||
IMoveInput* input = nullptr;
|
||||
bool autoJumpEnabled = true;
|
||||
protected:
|
||||
MinecraftClient& minecraft;
|
||||
int jumpTriggerTime;
|
||||
int ascendTriggerTime;
|
||||
int descendTriggerTime;
|
||||
bool ascending, descending;
|
||||
private:
|
||||
// local player fly
|
||||
// -----------------------
|
||||
float flyX, flyY, flyZ;
|
||||
|
||||
// smooth camera settings
|
||||
SmoothFloat smoothFlyX;
|
||||
SmoothFloat smoothFlyY;
|
||||
SmoothFloat smoothFlyZ;
|
||||
|
||||
int autoJumpTime;
|
||||
|
||||
int sentInventoryItemId = -1;
|
||||
int sentInventoryItemData = -1;
|
||||
|
||||
int armorTypeHash = 0;
|
||||
|
||||
// sprinting
|
||||
bool sprinting = false;
|
||||
int sprintDoubleTapTimer = 0;
|
||||
bool prevForwardHeld = false;
|
||||
public:
|
||||
void setSprinting(bool sprint) { sprinting = sprint; }
|
||||
};
|
||||
|
||||
|
||||
@@ -1,21 +1,19 @@
|
||||
#ifndef NET_MINECRAFT_CLIENT_PLAYER__RemotePlayer_H__
|
||||
#define NET_MINECRAFT_CLIENT_PLAYER__RemotePlayer_H__
|
||||
|
||||
//package net.minecraft.client.player;
|
||||
|
||||
#include "../../world/entity/player/Player.h"
|
||||
|
||||
class Level;
|
||||
|
||||
class RemotePlayer: public Player
|
||||
{
|
||||
typedef Player super;
|
||||
public:
|
||||
RemotePlayer(Level* level, bool isCreative);
|
||||
void aiStep();
|
||||
void tick();
|
||||
private:
|
||||
bool hasStartedUsingItem;
|
||||
};
|
||||
|
||||
#endif /*NET_MINECRAFT_CLIENT_PLAYER__RemotePlayer_H__*/
|
||||
#pragma once
|
||||
|
||||
//package net.minecraft.client.player;
|
||||
|
||||
#include "../../world/entity/player/Player.h"
|
||||
|
||||
class Level;
|
||||
|
||||
class RemotePlayer: public Player
|
||||
{
|
||||
typedef Player super;
|
||||
public:
|
||||
RemotePlayer(Level* level, bool isCreative);
|
||||
void aiStep();
|
||||
void tick();
|
||||
private:
|
||||
bool hasStartedUsingItem;
|
||||
};
|
||||
|
||||
|
||||
@@ -1,69 +1,67 @@
|
||||
#ifndef NET_MINECRAFT_CLIENT_PLAYER_INPUT_ControllerTurnInput_H__
|
||||
#define NET_MINECRAFT_CLIENT_PLAYER_INPUT_ControllerTurnInput_H__
|
||||
|
||||
#include "ITurnInput.h"
|
||||
#include "../../../platform/input/Controller.h"
|
||||
|
||||
/** A Controller Turn input */
|
||||
class ControllerTurnInput : public ITurnInput {
|
||||
public:
|
||||
static const int MODE_OFFSET = 1;
|
||||
static const int MODE_DELTA = 2;
|
||||
|
||||
ControllerTurnInput(int controllerId, int mode_)
|
||||
: cid(controllerId),
|
||||
mode(mode_),
|
||||
cxO(0), cyO(0),
|
||||
wasActive(false)
|
||||
{}
|
||||
|
||||
bool isTouched() { return Controller::isTouched(cid); }
|
||||
|
||||
TurnDelta getTurnDelta() {
|
||||
float dx = 0, dy = 0;
|
||||
bool isActive = Controller::isTouched(cid);
|
||||
|
||||
if (MODE_OFFSET == mode) {
|
||||
float dt = getDeltaTime();
|
||||
const float MaxTurnX = 250.0f;
|
||||
const float MaxTurnY = 200.0f;
|
||||
float cx = isActive? Controller::getX(cid) : cxO * 0.7f;
|
||||
float cy = isActive? Controller::getY(cid) : cyO * 0.7f;
|
||||
dx = linearTransform( cx, 0.1f, MaxTurnX ) * dt;
|
||||
dy = linearTransform( cy, 0.1f, MaxTurnY ) * dt;
|
||||
cxO = cx;
|
||||
cyO = cy;
|
||||
} else
|
||||
if (MODE_DELTA == mode && (wasActive || isActive)) {
|
||||
float cx = Controller::getX(cid);
|
||||
float cy = Controller::getY(cid);
|
||||
|
||||
// const float dt = getDeltaTime();
|
||||
const float MaxTurnX = 100.0f;
|
||||
const float MaxTurnY = 100.0f;
|
||||
const float DeadZone = 0;//0.25f * dt;//0.02f;
|
||||
|
||||
if (!wasActive) {
|
||||
cxO = cx;
|
||||
cyO = cy;
|
||||
}
|
||||
if (isActive) {
|
||||
dx = linearTransform(cx - cxO, DeadZone) * MaxTurnX;
|
||||
dy = linearTransform(cy - cyO, DeadZone) * MaxTurnY;
|
||||
cxO = cx;
|
||||
cyO = cy;
|
||||
}
|
||||
}
|
||||
|
||||
wasActive = isActive;
|
||||
return TurnDelta(dx, -dy);
|
||||
}
|
||||
|
||||
int mode;
|
||||
private:
|
||||
int cid;
|
||||
float cxO, cyO;
|
||||
bool wasActive;
|
||||
};
|
||||
|
||||
#endif /*NET_MINECRAFT_CLIENT_PLAYER_INPUT_ControllerTurnInput_H__*/
|
||||
#pragma once
|
||||
|
||||
#include "ITurnInput.h"
|
||||
#include "../../../platform/input/Controller.h"
|
||||
|
||||
/** A Controller Turn input */
|
||||
class ControllerTurnInput : public ITurnInput {
|
||||
public:
|
||||
static const int MODE_OFFSET = 1;
|
||||
static const int MODE_DELTA = 2;
|
||||
|
||||
ControllerTurnInput(int controllerId, int mode_)
|
||||
: cid(controllerId),
|
||||
mode(mode_),
|
||||
cxO(0), cyO(0),
|
||||
wasActive(false)
|
||||
{}
|
||||
|
||||
bool isTouched() { return Controller::isTouched(cid); }
|
||||
|
||||
TurnDelta getTurnDelta() {
|
||||
float dx = 0, dy = 0;
|
||||
bool isActive = Controller::isTouched(cid);
|
||||
|
||||
if (MODE_OFFSET == mode) {
|
||||
float dt = getDeltaTime();
|
||||
const float MaxTurnX = 250.0f;
|
||||
const float MaxTurnY = 200.0f;
|
||||
float cx = isActive? Controller::getX(cid) : cxO * 0.7f;
|
||||
float cy = isActive? Controller::getY(cid) : cyO * 0.7f;
|
||||
dx = linearTransform( cx, 0.1f, MaxTurnX ) * dt;
|
||||
dy = linearTransform( cy, 0.1f, MaxTurnY ) * dt;
|
||||
cxO = cx;
|
||||
cyO = cy;
|
||||
} else
|
||||
if (MODE_DELTA == mode && (wasActive || isActive)) {
|
||||
float cx = Controller::getX(cid);
|
||||
float cy = Controller::getY(cid);
|
||||
|
||||
// const float dt = getDeltaTime();
|
||||
const float MaxTurnX = 100.0f;
|
||||
const float MaxTurnY = 100.0f;
|
||||
const float DeadZone = 0;//0.25f * dt;//0.02f;
|
||||
|
||||
if (!wasActive) {
|
||||
cxO = cx;
|
||||
cyO = cy;
|
||||
}
|
||||
if (isActive) {
|
||||
dx = linearTransform(cx - cxO, DeadZone) * MaxTurnX;
|
||||
dy = linearTransform(cy - cyO, DeadZone) * MaxTurnY;
|
||||
cxO = cx;
|
||||
cyO = cy;
|
||||
}
|
||||
}
|
||||
|
||||
wasActive = isActive;
|
||||
return TurnDelta(dx, -dy);
|
||||
}
|
||||
|
||||
int mode;
|
||||
private:
|
||||
int cid;
|
||||
float cxO, cyO;
|
||||
bool wasActive;
|
||||
};
|
||||
|
||||
|
||||
@@ -1,45 +1,43 @@
|
||||
#ifndef NET_MINECRAFT_CLIENT_PLAYER_INPUT__IBuildInput_H__
|
||||
#define NET_MINECRAFT_CLIENT_PLAYER_INPUT__IBuildInput_H__
|
||||
|
||||
#include "../../IConfigListener.h"
|
||||
class Player;
|
||||
|
||||
class BuildActionIntention {
|
||||
public:
|
||||
BuildActionIntention()
|
||||
: action(0)
|
||||
{}
|
||||
BuildActionIntention(int action)
|
||||
: action(action)
|
||||
{}
|
||||
|
||||
bool isFirstRemove() { return (action & BAI_FIRSTREMOVE) != 0; }
|
||||
bool isRemoveContinue() { return (action & BAI_REMOVE) != 0; }
|
||||
|
||||
bool isBuild() { return (action & BAI_BUILD) != 0; }
|
||||
bool isRemove() { return isFirstRemove() || isRemoveContinue(); }
|
||||
|
||||
bool isAttack() { return (action & BAI_ATTACK) != 0; }
|
||||
bool isInteract() { return (action & BAI_INTERACT) != 0; }
|
||||
|
||||
int action;
|
||||
|
||||
static const int BAI_BUILD = 1;
|
||||
static const int BAI_REMOVE = 2;
|
||||
static const int BAI_FIRSTREMOVE = 4;
|
||||
|
||||
static const int BAI_ATTACK = 8;
|
||||
static const int BAI_INTERACT = 16;
|
||||
};
|
||||
|
||||
|
||||
class IBuildInput: public IConfigListener {
|
||||
public:
|
||||
virtual ~IBuildInput(){}
|
||||
|
||||
virtual void onConfigChanged(const Config& c) {}
|
||||
// @return true if user wants to do an action, false if not
|
||||
virtual bool tickBuild(Player*, BuildActionIntention* bai) { return false; }
|
||||
};
|
||||
|
||||
#endif /*NET_MINECRAFT_CLIENT_PLAYER_INPUT__IBuildInput_H__*/
|
||||
#pragma once
|
||||
|
||||
#include "../../IConfigListener.h"
|
||||
class Player;
|
||||
|
||||
class BuildActionIntention {
|
||||
public:
|
||||
BuildActionIntention()
|
||||
: action(0)
|
||||
{}
|
||||
BuildActionIntention(int action)
|
||||
: action(action)
|
||||
{}
|
||||
|
||||
bool isFirstRemove() { return (action & BAI_FIRSTREMOVE) != 0; }
|
||||
bool isRemoveContinue() { return (action & BAI_REMOVE) != 0; }
|
||||
|
||||
bool isBuild() { return (action & BAI_BUILD) != 0; }
|
||||
bool isRemove() { return isFirstRemove() || isRemoveContinue(); }
|
||||
|
||||
bool isAttack() { return (action & BAI_ATTACK) != 0; }
|
||||
bool isInteract() { return (action & BAI_INTERACT) != 0; }
|
||||
|
||||
int action;
|
||||
|
||||
static const int BAI_BUILD = 1;
|
||||
static const int BAI_REMOVE = 2;
|
||||
static const int BAI_FIRSTREMOVE = 4;
|
||||
|
||||
static const int BAI_ATTACK = 8;
|
||||
static const int BAI_INTERACT = 16;
|
||||
};
|
||||
|
||||
|
||||
class IBuildInput: public IConfigListener {
|
||||
public:
|
||||
virtual ~IBuildInput(){}
|
||||
|
||||
virtual void onConfigChanged(const Config& c) {}
|
||||
// @return true if user wants to do an action, false if not
|
||||
virtual bool tickBuild(Player*, BuildActionIntention* bai) { return false; }
|
||||
};
|
||||
|
||||
|
||||
@@ -1,75 +1,73 @@
|
||||
#ifndef NET_MINECRAFT_CLIENT_PLAYER__IInputHolder_H__
|
||||
#define NET_MINECRAFT_CLIENT_PLAYER__IInputHolder_H__
|
||||
|
||||
#include "IMoveInput.h"
|
||||
#include "ITurnInput.h"
|
||||
#include "IBuildInput.h"
|
||||
|
||||
#include "../../../platform/input/Mouse.h"
|
||||
|
||||
class Player;
|
||||
|
||||
class IInputHolder: public IConfigListener
|
||||
{
|
||||
public:
|
||||
IInputHolder()
|
||||
: mousex(0),
|
||||
mousey(0),
|
||||
alpha(0)
|
||||
{}
|
||||
|
||||
virtual ~IInputHolder() {}
|
||||
|
||||
virtual void render(float alpha) {}
|
||||
|
||||
virtual bool allowPicking() {
|
||||
mousex = Mouse::getX();
|
||||
mousey = Mouse::getY();
|
||||
return Mouse::getButtonState(MouseAction::ACTION_LEFT) == MouseAction::DATA_DOWN;
|
||||
}
|
||||
|
||||
void onConfigChanged(const Config& c) {
|
||||
getMoveInput()->onConfigChanged(c);
|
||||
getTurnInput()->onConfigChanged(c);
|
||||
getBuildInput()->onConfigChanged(c);
|
||||
}
|
||||
|
||||
virtual IMoveInput* getMoveInput() = 0;
|
||||
virtual ITurnInput* getTurnInput() = 0;
|
||||
virtual IBuildInput* getBuildInput() = 0;
|
||||
|
||||
float mousex, mousey;
|
||||
float alpha;
|
||||
};
|
||||
|
||||
|
||||
class CustomInputHolder: public IInputHolder
|
||||
{
|
||||
public:
|
||||
CustomInputHolder(IMoveInput* move, ITurnInput* turn, IBuildInput* build)
|
||||
{
|
||||
setInputs(move, turn, build);
|
||||
}
|
||||
|
||||
~CustomInputHolder() {
|
||||
delete _move;
|
||||
delete _turn;
|
||||
delete _build;
|
||||
}
|
||||
void setInputs(IMoveInput* move, ITurnInput* turn, IBuildInput* build) {
|
||||
_move = move;
|
||||
_turn = turn;
|
||||
_build = build;
|
||||
}
|
||||
|
||||
virtual IMoveInput* getMoveInput() { return _move; }
|
||||
virtual ITurnInput* getTurnInput() { return _turn; }
|
||||
virtual IBuildInput* getBuildInput() { return _build; }
|
||||
|
||||
private:
|
||||
IMoveInput* _move;
|
||||
ITurnInput* _turn;
|
||||
IBuildInput* _build;
|
||||
};
|
||||
|
||||
#endif /*NET_MINECRAFT_CLIENT_PLAYER__IInputHolder_H__*/
|
||||
#pragma once
|
||||
|
||||
#include "IMoveInput.h"
|
||||
#include "ITurnInput.h"
|
||||
#include "IBuildInput.h"
|
||||
|
||||
#include "../../../platform/input/Mouse.h"
|
||||
|
||||
class Player;
|
||||
|
||||
class IInputHolder: public IConfigListener
|
||||
{
|
||||
public:
|
||||
IInputHolder()
|
||||
: mousex(0),
|
||||
mousey(0),
|
||||
alpha(0)
|
||||
{}
|
||||
|
||||
virtual ~IInputHolder() {}
|
||||
|
||||
virtual void render(float alpha) {}
|
||||
|
||||
virtual bool allowPicking() {
|
||||
mousex = Mouse::getX();
|
||||
mousey = Mouse::getY();
|
||||
return Mouse::getButtonState(MouseAction::ACTION_LEFT) == MouseAction::DATA_DOWN;
|
||||
}
|
||||
|
||||
void onConfigChanged(const Config& c) {
|
||||
getMoveInput()->onConfigChanged(c);
|
||||
getTurnInput()->onConfigChanged(c);
|
||||
getBuildInput()->onConfigChanged(c);
|
||||
}
|
||||
|
||||
virtual IMoveInput* getMoveInput() = 0;
|
||||
virtual ITurnInput* getTurnInput() = 0;
|
||||
virtual IBuildInput* getBuildInput() = 0;
|
||||
|
||||
float mousex, mousey;
|
||||
float alpha;
|
||||
};
|
||||
|
||||
|
||||
class CustomInputHolder: public IInputHolder
|
||||
{
|
||||
public:
|
||||
CustomInputHolder(IMoveInput* move, ITurnInput* turn, IBuildInput* build)
|
||||
{
|
||||
setInputs(move, turn, build);
|
||||
}
|
||||
|
||||
~CustomInputHolder() {
|
||||
delete _move;
|
||||
delete _turn;
|
||||
delete _build;
|
||||
}
|
||||
void setInputs(IMoveInput* move, ITurnInput* turn, IBuildInput* build) {
|
||||
_move = move;
|
||||
_turn = turn;
|
||||
_build = build;
|
||||
}
|
||||
|
||||
virtual IMoveInput* getMoveInput() { return _move; }
|
||||
virtual ITurnInput* getTurnInput() { return _turn; }
|
||||
virtual IBuildInput* getBuildInput() { return _build; }
|
||||
|
||||
private:
|
||||
IMoveInput* _move;
|
||||
ITurnInput* _turn;
|
||||
IBuildInput* _build;
|
||||
};
|
||||
|
||||
|
||||
@@ -1,47 +1,45 @@
|
||||
#ifndef NET_MINECRAFT_CLIENT_PLAYER__IMoveInput_H__
|
||||
#define NET_MINECRAFT_CLIENT_PLAYER__IMoveInput_H__
|
||||
|
||||
//package net.minecraft.client.player;
|
||||
|
||||
#include "../../IConfigListener.h"
|
||||
class Player;
|
||||
class Minecraft;
|
||||
|
||||
class IMoveInput
|
||||
{
|
||||
protected:
|
||||
IMoveInput()
|
||||
: xa(0),
|
||||
ya(0),
|
||||
wasJumping(false),
|
||||
jumping(false),
|
||||
sneaking(false),
|
||||
wantUp(false),
|
||||
wantDown(false),
|
||||
isChangingFlightHeight(false)
|
||||
{}
|
||||
public:
|
||||
virtual ~IMoveInput() {}
|
||||
|
||||
virtual void tick(Player* player) {}
|
||||
virtual void render(float a) {}
|
||||
|
||||
virtual void setKey(int eventKey, bool eventKeyState) {}
|
||||
virtual void releaseAllKeys() {}
|
||||
|
||||
virtual void onConfigChanged(const Config& c) {}
|
||||
|
||||
public:
|
||||
float xa;
|
||||
float ya;
|
||||
|
||||
bool wasJumping;
|
||||
bool jumping;
|
||||
bool sneaking;
|
||||
|
||||
bool wantUp;
|
||||
bool wantDown;
|
||||
bool isChangingFlightHeight;
|
||||
};
|
||||
|
||||
#endif /*NET_MINECRAFT_CLIENT_PLAYER__IMoveInput_H__*/
|
||||
#pragma once
|
||||
|
||||
//package net.minecraft.client.player;
|
||||
|
||||
#include "../../IConfigListener.h"
|
||||
class Player;
|
||||
class Minecraft;
|
||||
|
||||
class IMoveInput
|
||||
{
|
||||
protected:
|
||||
IMoveInput()
|
||||
: xa(0),
|
||||
ya(0),
|
||||
wasJumping(false),
|
||||
jumping(false),
|
||||
sneaking(false),
|
||||
wantUp(false),
|
||||
wantDown(false),
|
||||
isChangingFlightHeight(false)
|
||||
{}
|
||||
public:
|
||||
virtual ~IMoveInput() {}
|
||||
|
||||
virtual void tick(Player* player) {}
|
||||
virtual void render(float a) {}
|
||||
|
||||
virtual void setKey(int eventKey, bool eventKeyState) {}
|
||||
virtual void releaseAllKeys() {}
|
||||
|
||||
virtual void onConfigChanged(const Config& c) {}
|
||||
|
||||
public:
|
||||
float xa;
|
||||
float ya;
|
||||
|
||||
bool wasJumping;
|
||||
bool jumping;
|
||||
bool sneaking;
|
||||
|
||||
bool wantUp;
|
||||
bool wantDown;
|
||||
bool isChangingFlightHeight;
|
||||
};
|
||||
|
||||
|
||||
@@ -1,52 +1,50 @@
|
||||
#ifndef NET_MINECRAFT_CLIENT_PLAYER__ITurnInput_H__
|
||||
#define NET_MINECRAFT_CLIENT_PLAYER__ITurnInput_H__
|
||||
|
||||
#include "../../../platform/time.h"
|
||||
#include "../../IConfigListener.h"
|
||||
#include <cmath>
|
||||
|
||||
/** Representing a Turn delta value */
|
||||
class TurnDelta {
|
||||
public:
|
||||
TurnDelta(float dx, float dy)
|
||||
: x(dx),
|
||||
y(dy)
|
||||
{}
|
||||
|
||||
float x, y;
|
||||
};
|
||||
|
||||
/** Base class for classes providing TurnDeltas */
|
||||
class ITurnInput: public IConfigListener {
|
||||
public:
|
||||
virtual ~ITurnInput() {}
|
||||
virtual void onConfigChanged(const Config& c) {}
|
||||
|
||||
virtual TurnDelta getTurnDelta() = 0;
|
||||
protected:
|
||||
ITurnInput()
|
||||
: _lastTime(-1.0f)
|
||||
{}
|
||||
|
||||
float getDeltaTime(){
|
||||
if (_lastTime == -1.0f) {
|
||||
_lastTime = getTimeS();
|
||||
}
|
||||
float now = getTimeS();
|
||||
float dt = now - _lastTime;
|
||||
_lastTime = now;
|
||||
return dt;
|
||||
}
|
||||
|
||||
static float linearTransform(float value, float deadZone, float scale=1.0f, bool limit1=false) {
|
||||
float deadSigned = value >= 0? deadZone : -deadZone;
|
||||
if (std::abs(deadSigned) >= std::abs(value)) return 0;
|
||||
float ret = (value - deadSigned) * scale;
|
||||
if (limit1 && std::abs(ret) > 1) ret /= std::abs(ret);
|
||||
return ret;
|
||||
}
|
||||
private:
|
||||
float _lastTime;
|
||||
};
|
||||
|
||||
#endif /*NET_MINECRAFT_CLIENT_PLAYER__ITurnInput_H__*/
|
||||
#pragma once
|
||||
|
||||
#include "../../../platform/time.h"
|
||||
#include "../../IConfigListener.h"
|
||||
#include <cmath>
|
||||
|
||||
/** Representing a Turn delta value */
|
||||
class TurnDelta {
|
||||
public:
|
||||
TurnDelta(float dx, float dy)
|
||||
: x(dx),
|
||||
y(dy)
|
||||
{}
|
||||
|
||||
float x, y;
|
||||
};
|
||||
|
||||
/** Base class for classes providing TurnDeltas */
|
||||
class ITurnInput: public IConfigListener {
|
||||
public:
|
||||
virtual ~ITurnInput() {}
|
||||
virtual void onConfigChanged(const Config& c) {}
|
||||
|
||||
virtual TurnDelta getTurnDelta() = 0;
|
||||
protected:
|
||||
ITurnInput()
|
||||
: _lastTime(-1.0f)
|
||||
{}
|
||||
|
||||
float getDeltaTime(){
|
||||
if (_lastTime == -1.0f) {
|
||||
_lastTime = getTimeS();
|
||||
}
|
||||
float now = getTimeS();
|
||||
float dt = now - _lastTime;
|
||||
_lastTime = now;
|
||||
return dt;
|
||||
}
|
||||
|
||||
static float linearTransform(float value, float deadZone, float scale=1.0f, bool limit1=false) {
|
||||
float deadSigned = value >= 0? deadZone : -deadZone;
|
||||
if (std::abs(deadSigned) >= std::abs(value)) return 0;
|
||||
float ret = (value - deadSigned) * scale;
|
||||
if (limit1 && std::abs(ret) > 1) ret /= std::abs(ret);
|
||||
return ret;
|
||||
}
|
||||
private:
|
||||
float _lastTime;
|
||||
};
|
||||
|
||||
|
||||
@@ -1,36 +1,34 @@
|
||||
#ifndef NET_MINECRAFT_CLIENT_PLAYER__KeyboardInput_H__
|
||||
#define NET_MINECRAFT_CLIENT_PLAYER__KeyboardInput_H__
|
||||
|
||||
//package net.minecraft.client.player;
|
||||
|
||||
#include "IMoveInput.h"
|
||||
|
||||
class Options;
|
||||
class Player;
|
||||
|
||||
// @todo: extract a separate MoveInput (-> merge XperiaPlayInput)
|
||||
class KeyboardInput: public IMoveInput
|
||||
{
|
||||
static const int NumKeys = 10;
|
||||
public:
|
||||
static const int KEY_UP = 0;
|
||||
static const int KEY_DOWN = 1;
|
||||
static const int KEY_LEFT = 2;
|
||||
static const int KEY_RIGHT = 3;
|
||||
static const int KEY_JUMP = 4;
|
||||
static const int KEY_SNEAK = 5;
|
||||
static const int KEY_CRAFT = 6;
|
||||
|
||||
KeyboardInput(Options* options);
|
||||
|
||||
void tick(Player* player);
|
||||
|
||||
void setKey(int key, bool state);
|
||||
void releaseAllKeys();
|
||||
|
||||
protected:
|
||||
bool keys[NumKeys];
|
||||
Options* options;
|
||||
};
|
||||
|
||||
#endif /*NET_MINECRAFT_CLIENT_PLAYER__KeyboardInput_H__*/
|
||||
#pragma once
|
||||
|
||||
//package net.minecraft.client.player;
|
||||
|
||||
#include "IMoveInput.h"
|
||||
|
||||
class Options;
|
||||
class Player;
|
||||
|
||||
// @todo: extract a separate MoveInput (-> merge XperiaPlayInput)
|
||||
class KeyboardInput: public IMoveInput
|
||||
{
|
||||
static const int NumKeys = 10;
|
||||
public:
|
||||
static const int KEY_UP = 0;
|
||||
static const int KEY_DOWN = 1;
|
||||
static const int KEY_LEFT = 2;
|
||||
static const int KEY_RIGHT = 3;
|
||||
static const int KEY_JUMP = 4;
|
||||
static const int KEY_SNEAK = 5;
|
||||
static const int KEY_CRAFT = 6;
|
||||
|
||||
KeyboardInput(Options* options);
|
||||
|
||||
void tick(Player* player);
|
||||
|
||||
void setKey(int key, bool state);
|
||||
void releaseAllKeys();
|
||||
|
||||
protected:
|
||||
bool keys[NumKeys];
|
||||
Options* options;
|
||||
};
|
||||
|
||||
|
||||
@@ -1,36 +1,34 @@
|
||||
#ifndef NET_MINECRAFT_CLIENT_PLAYER_INPUT_MouseBuildInput_H__
|
||||
#define NET_MINECRAFT_CLIENT_PLAYER_INPUT_MouseBuildInput_H__
|
||||
|
||||
#include "IBuildInput.h"
|
||||
#include "../../../platform/input/Mouse.h"
|
||||
|
||||
/** A Mouse Build input */
|
||||
class MouseBuildInput : public IBuildInput {
|
||||
public:
|
||||
MouseBuildInput()
|
||||
: buildDelayTicks(10),
|
||||
buildHoldTicks(0)
|
||||
{}
|
||||
|
||||
virtual bool tickBuild(Player* p, BuildActionIntention* bai) {
|
||||
if (Mouse::getButtonState(MouseAction::ACTION_LEFT) != 0) {
|
||||
*bai = BuildActionIntention(BuildActionIntention::BAI_REMOVE | BuildActionIntention::BAI_ATTACK);
|
||||
return true;
|
||||
}
|
||||
if (Mouse::getButtonState(MouseAction::ACTION_RIGHT) != 0) {
|
||||
if (buildHoldTicks >= buildDelayTicks) buildHoldTicks = 0;
|
||||
if (++buildHoldTicks == 1) {
|
||||
*bai = BuildActionIntention(BuildActionIntention::BAI_BUILD | BuildActionIntention::BAI_INTERACT);
|
||||
return true;
|
||||
}
|
||||
} else {
|
||||
buildHoldTicks = 0;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
private:
|
||||
int buildHoldTicks;
|
||||
int buildDelayTicks;
|
||||
};
|
||||
|
||||
#endif /*NET_MINECRAFT_CLIENT_PLAYER_INPUT_MouseBuildInput_H__*/
|
||||
#pragma once
|
||||
|
||||
#include "IBuildInput.h"
|
||||
#include "../../../platform/input/Mouse.h"
|
||||
|
||||
/** A Mouse Build input */
|
||||
class MouseBuildInput : public IBuildInput {
|
||||
public:
|
||||
MouseBuildInput()
|
||||
: buildDelayTicks(10),
|
||||
buildHoldTicks(0)
|
||||
{}
|
||||
|
||||
virtual bool tickBuild(Player* p, BuildActionIntention* bai) {
|
||||
if (Mouse::getButtonState(MouseAction::ACTION_LEFT) != 0) {
|
||||
*bai = BuildActionIntention(BuildActionIntention::BAI_REMOVE | BuildActionIntention::BAI_ATTACK);
|
||||
return true;
|
||||
}
|
||||
if (Mouse::getButtonState(MouseAction::ACTION_RIGHT) != 0) {
|
||||
if (buildHoldTicks >= buildDelayTicks) buildHoldTicks = 0;
|
||||
if (++buildHoldTicks == 1) {
|
||||
*bai = BuildActionIntention(BuildActionIntention::BAI_BUILD | BuildActionIntention::BAI_INTERACT);
|
||||
return true;
|
||||
}
|
||||
} else {
|
||||
buildHoldTicks = 0;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
private:
|
||||
int buildHoldTicks;
|
||||
int buildDelayTicks;
|
||||
};
|
||||
|
||||
|
||||
@@ -1,43 +1,41 @@
|
||||
#ifndef NET_MINECRAFT_CLIENT_PLAYER_INPUT_MouseTurnInput_H__
|
||||
#define NET_MINECRAFT_CLIENT_PLAYER_INPUT_MouseTurnInput_H__
|
||||
|
||||
#include "ITurnInput.h"
|
||||
#include "../../../platform/input/Mouse.h"
|
||||
|
||||
/** A Mouse Turn input */
|
||||
class MouseTurnInput : public ITurnInput {
|
||||
public:
|
||||
static const int MODE_OFFSET = 1;
|
||||
static const int MODE_DELTA = 2;
|
||||
|
||||
MouseTurnInput(int mode_, int centerX, int centerY)
|
||||
: mode(mode_),
|
||||
_centerX((float)centerX),
|
||||
_centerY((float)centerY)
|
||||
{}
|
||||
|
||||
void onConfigChanged(const Config& config) {
|
||||
_centerX = ((float) config.width ) * 0.5f;
|
||||
_centerY = ((float) config.height) * 0.5f;
|
||||
}
|
||||
|
||||
TurnDelta getTurnDelta() {
|
||||
float dx = 0, dy = 0;
|
||||
if ( MODE_DELTA == mode ) {
|
||||
dx = (float)Mouse::getDX();
|
||||
dy = (float)Mouse::getDY();
|
||||
} else if (MODE_OFFSET == mode) {
|
||||
float dt = getDeltaTime();
|
||||
dx = linearTransform( (float)Mouse::getX() - _centerX, 40, 0.4f ) * dt;
|
||||
dy = linearTransform( (float)Mouse::getY() - _centerY, 30, 0.6f ) * dt;
|
||||
}
|
||||
return TurnDelta(dx, dy);
|
||||
}
|
||||
|
||||
int mode;
|
||||
private:
|
||||
float _centerX;
|
||||
float _centerY;
|
||||
};
|
||||
|
||||
#endif /*NET_MINECRAFT_CLIENT_PLAYER_INPUT_MouseTurnInput_H__*/
|
||||
#pragma once
|
||||
|
||||
#include "ITurnInput.h"
|
||||
#include "../../../platform/input/Mouse.h"
|
||||
|
||||
/** A Mouse Turn input */
|
||||
class MouseTurnInput : public ITurnInput {
|
||||
public:
|
||||
static const int MODE_OFFSET = 1;
|
||||
static const int MODE_DELTA = 2;
|
||||
|
||||
MouseTurnInput(int mode_, int centerX, int centerY)
|
||||
: mode(mode_),
|
||||
_centerX((float)centerX),
|
||||
_centerY((float)centerY)
|
||||
{}
|
||||
|
||||
void onConfigChanged(const Config& config) {
|
||||
_centerX = ((float) config.width ) * 0.5f;
|
||||
_centerY = ((float) config.height) * 0.5f;
|
||||
}
|
||||
|
||||
TurnDelta getTurnDelta() {
|
||||
float dx = 0, dy = 0;
|
||||
if ( MODE_DELTA == mode ) {
|
||||
dx = (float)Mouse::getDX();
|
||||
dy = (float)Mouse::getDY();
|
||||
} else if (MODE_OFFSET == mode) {
|
||||
float dt = getDeltaTime();
|
||||
dx = linearTransform( (float)Mouse::getX() - _centerX, 40, 0.4f ) * dt;
|
||||
dy = linearTransform( (float)Mouse::getY() - _centerY, 30, 0.6f ) * dt;
|
||||
}
|
||||
return TurnDelta(dx, dy);
|
||||
}
|
||||
|
||||
int mode;
|
||||
private:
|
||||
float _centerX;
|
||||
float _centerY;
|
||||
};
|
||||
|
||||
|
||||
@@ -1,51 +1,49 @@
|
||||
#ifndef NET_MINECRAFT_CLIENT_PLAYER__XperiaPlayInput_H__
|
||||
#define NET_MINECRAFT_CLIENT_PLAYER__XperiaPlayInput_H__
|
||||
|
||||
//package net.minecraft.client.player;
|
||||
|
||||
#include "KeyboardInput.h"
|
||||
#include "platform/input/Controller.h"
|
||||
#include "world/entity/player/Player.h"
|
||||
|
||||
// @note: This is just copy-pasted from KeyboardInput right now.
|
||||
class XperiaPlayInput: public KeyboardInput
|
||||
{
|
||||
typedef KeyboardInput super;
|
||||
public:
|
||||
XperiaPlayInput(Options* options)
|
||||
: super(options),
|
||||
wasSneakTouched(false)
|
||||
{}
|
||||
|
||||
void tick(Player* player) {
|
||||
bool _sneaking = sneaking;
|
||||
super::tick(player);
|
||||
sneaking = _sneaking;
|
||||
|
||||
wantUp = (jumping && keys[KEY_UP]);
|
||||
wantDown = (jumping && keys[KEY_DOWN]);
|
||||
if ((wantUp | wantDown) && (player && player->abilities.flying)) ya = 0;
|
||||
|
||||
bool isSneakTouched = Controller::isTouched(1);
|
||||
if (isSneakTouched && !wasSneakTouched) {
|
||||
sneaking = !sneaking;
|
||||
}
|
||||
wasSneakTouched = isSneakTouched;
|
||||
|
||||
if (sneaking) {
|
||||
xa *= 0.3f;
|
||||
ya *= 0.3f;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
if (Controller::isTouched(moveStick)) {
|
||||
xa = -Controller::getTransformedX(moveStick, 0.1f, 1.25f, true);
|
||||
ya = +Controller::getTransformedY(moveStick, 0.1f, 1.25f, true);
|
||||
}
|
||||
*/
|
||||
private:
|
||||
bool wasSneakTouched;
|
||||
};
|
||||
|
||||
#endif /*NET_MINECRAFT_CLIENT_PLAYER__XperiaPlayInput_H__*/
|
||||
#pragma once
|
||||
|
||||
//package net.minecraft.client.player;
|
||||
|
||||
#include "KeyboardInput.h"
|
||||
#include "platform/input/Controller.h"
|
||||
#include "world/entity/player/Player.h"
|
||||
|
||||
// @note: This is just copy-pasted from KeyboardInput right now.
|
||||
class XperiaPlayInput: public KeyboardInput
|
||||
{
|
||||
typedef KeyboardInput super;
|
||||
public:
|
||||
XperiaPlayInput(Options* options)
|
||||
: super(options),
|
||||
wasSneakTouched(false)
|
||||
{}
|
||||
|
||||
void tick(Player* player) {
|
||||
bool _sneaking = sneaking;
|
||||
super::tick(player);
|
||||
sneaking = _sneaking;
|
||||
|
||||
wantUp = (jumping && keys[KEY_UP]);
|
||||
wantDown = (jumping && keys[KEY_DOWN]);
|
||||
if ((wantUp | wantDown) && (player && player->abilities.flying)) ya = 0;
|
||||
|
||||
bool isSneakTouched = Controller::isTouched(1);
|
||||
if (isSneakTouched && !wasSneakTouched) {
|
||||
sneaking = !sneaking;
|
||||
}
|
||||
wasSneakTouched = isSneakTouched;
|
||||
|
||||
if (sneaking) {
|
||||
xa *= 0.3f;
|
||||
ya *= 0.3f;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
if (Controller::isTouched(moveStick)) {
|
||||
xa = -Controller::getTransformedX(moveStick, 0.1f, 1.25f, true);
|
||||
ya = +Controller::getTransformedY(moveStick, 0.1f, 1.25f, true);
|
||||
}
|
||||
*/
|
||||
private:
|
||||
bool wasSneakTouched;
|
||||
};
|
||||
|
||||
|
||||
@@ -1,14 +1,12 @@
|
||||
#ifndef NET_MINECRAFT_CLIENT_PLAYER__ITouchScreenModel_H__
|
||||
#define NET_MINECRAFT_CLIENT_PLAYER__ITouchScreenModel_H__
|
||||
|
||||
#include "../../../../platform/input/Mouse.h"
|
||||
|
||||
class ITouchScreenModel
|
||||
{
|
||||
public:
|
||||
virtual ~ITouchScreenModel() {}
|
||||
virtual int getPointerId(const MouseAction& m) { return m.pointerId; }
|
||||
virtual int getPointerId(int x, int y, int pid) { return pid; }
|
||||
};
|
||||
|
||||
#endif /*NET_MINECRAFT_CLIENT_PLAYER__ITouchScreenModel_H__*/
|
||||
#pragma once
|
||||
|
||||
#include "../../../../platform/input/Mouse.h"
|
||||
|
||||
class ITouchScreenModel
|
||||
{
|
||||
public:
|
||||
virtual ~ITouchScreenModel() {}
|
||||
virtual int getPointerId(const MouseAction& m) { return m.pointerId; }
|
||||
virtual int getPointerId(int x, int y, int pid) { return pid; }
|
||||
};
|
||||
|
||||
|
||||
@@ -1,339 +1,337 @@
|
||||
#ifndef NET_MINECRAFT_CLIENT_PLAYER__TouchAreaModel_H__
|
||||
#define NET_MINECRAFT_CLIENT_PLAYER__TouchAreaModel_H__
|
||||
|
||||
#include "ITouchScreenModel.h"
|
||||
#include <vector>
|
||||
#include "../../../../platform/time.h"
|
||||
|
||||
/// Interface for an area that can be point tested
|
||||
class IArea{
|
||||
public:
|
||||
IArea()
|
||||
: deleteMe(true)
|
||||
{}
|
||||
|
||||
virtual ~IArea() {};
|
||||
virtual bool isInside(float x, float y) = 0;
|
||||
//virtual void expandRectToInclude(float& l, float& t, float& r, float& b) {}
|
||||
|
||||
bool deleteMe;
|
||||
};
|
||||
|
||||
/// Holder for multiple <IArea, int areaId> pairs
|
||||
class TouchAreaModel: public ITouchScreenModel
|
||||
{
|
||||
public:
|
||||
TouchAreaModel() {}
|
||||
|
||||
~TouchAreaModel() {
|
||||
clear();
|
||||
}
|
||||
|
||||
void clear() {
|
||||
for (unsigned int i = 0; i < _areas.size(); ++i) {
|
||||
Area* a = _areas[i];
|
||||
if (a->area && a->area->deleteMe)
|
||||
delete a->area;
|
||||
delete a;
|
||||
}
|
||||
_areas.clear();
|
||||
}
|
||||
|
||||
int getPointerId(const MouseAction& m) {
|
||||
return getPointerId(m.x, m.y, m.pointerId);
|
||||
}
|
||||
|
||||
int getPointerId(int x, int y, int pid) {
|
||||
//static Stopwatch w;
|
||||
//w.printEvery(200, "IArea");
|
||||
//w.start();
|
||||
float fx = (float)x, fy = (float) y;
|
||||
for (unsigned int i = 0; i < _areas.size(); ++i) {
|
||||
const Area* a = _areas[i];
|
||||
if (a->area->isInside(fx, fy)) {
|
||||
//w.stop();
|
||||
return a->areaId;
|
||||
}
|
||||
}
|
||||
//w.stop();
|
||||
return pid;
|
||||
}
|
||||
|
||||
void addArea(int areaId, IArea* area) {
|
||||
Area* a = new Area();
|
||||
a->area = area;
|
||||
a->areaId = areaId;
|
||||
|
||||
_areas.push_back( a );
|
||||
}
|
||||
|
||||
private:
|
||||
struct Area {
|
||||
IArea* area;
|
||||
int areaId;
|
||||
};
|
||||
|
||||
std::vector<Area*> _areas;
|
||||
};
|
||||
|
||||
/// Area represented by a polygon
|
||||
class PolygonArea: public IArea
|
||||
{
|
||||
public:
|
||||
PolygonArea(int numPoints, const float* xp, const float* yp)
|
||||
: _numPoints(numPoints)
|
||||
{
|
||||
_x = new float[numPoints];
|
||||
_y = new float[numPoints];
|
||||
|
||||
for (int i = 0; i < numPoints; ++i) {
|
||||
_x[i] = xp[i];
|
||||
_y[i] = yp[i];
|
||||
}
|
||||
}
|
||||
|
||||
~PolygonArea() {
|
||||
delete[] _x;
|
||||
delete[] _y;
|
||||
}
|
||||
|
||||
virtual bool isInside(float x, float y)
|
||||
{
|
||||
bool c = false;
|
||||
for (int i = 0, j = _numPoints-1; i < _numPoints; j = i++) {
|
||||
if ((((_y[i] <= y) && (y < _y[j])) ||
|
||||
((_y[j] <= y) && (y < _y[i]))) &&
|
||||
(x < (_x[j] - _x[i]) * (y - _y[i]) / (_y[j] - _y[i]) + _x[i]))
|
||||
c = !c;
|
||||
}
|
||||
return c == 1;
|
||||
}
|
||||
|
||||
//private:
|
||||
float* _x;
|
||||
float* _y;
|
||||
int _numPoints;
|
||||
};
|
||||
|
||||
/// Area represented by a rectangle
|
||||
class RectangleArea: public IArea
|
||||
{
|
||||
public:
|
||||
RectangleArea(float x0, float y0, float x1, float y1)
|
||||
: _x0(x0),
|
||||
_x1(x1),
|
||||
_y0(y0),
|
||||
_y1(y1)
|
||||
{}
|
||||
|
||||
virtual bool isInside(float x, float y) {
|
||||
return x >= _x0 && x <= _x1
|
||||
&& y >= _y0 && y <= _y1;
|
||||
}
|
||||
|
||||
virtual float centerX()
|
||||
{
|
||||
return _x0 + (_x1 - _x0) * .5f;
|
||||
}
|
||||
|
||||
virtual float centerY()
|
||||
{
|
||||
return _y0 + (_y1 - _y0) * .5f;
|
||||
}
|
||||
|
||||
//private:
|
||||
float _x0, _x1;
|
||||
float _y0, _y1;
|
||||
};
|
||||
|
||||
/// An area represented by a circle
|
||||
class CircleArea: public IArea
|
||||
{
|
||||
public:
|
||||
CircleArea(float x, float y, float r)
|
||||
: _x(x), _y(y), _rr(r*r)
|
||||
{}
|
||||
|
||||
virtual bool isInside(float x, float y) {
|
||||
const float dx = x - _x;
|
||||
const float dy = y - _y;
|
||||
return (dx*dx + dy*dy) <= _rr;
|
||||
}
|
||||
|
||||
private:
|
||||
float _x, _y;
|
||||
float _rr;
|
||||
};
|
||||
|
||||
/// Inside any area in include list but none of exclude list
|
||||
class IncludeExcludeArea: public IArea
|
||||
{
|
||||
public:
|
||||
IncludeExcludeArea() {}
|
||||
|
||||
~IncludeExcludeArea() {
|
||||
clear();
|
||||
}
|
||||
|
||||
void clear() {
|
||||
if (deleteMe) {
|
||||
for (unsigned int i = 0; i < _includes.size(); ++i) {
|
||||
IArea* area = _includes[i];
|
||||
if (area->deleteMe) delete area;
|
||||
}
|
||||
for (unsigned int i = 0; i < _excludes.size(); ++i) {
|
||||
IArea* area = _excludes[i];
|
||||
if (area->deleteMe) delete area;
|
||||
}
|
||||
}
|
||||
_includes.clear();
|
||||
_excludes.clear();
|
||||
}
|
||||
|
||||
void include(IArea* area) { _includes.push_back(area); }
|
||||
void exclude(IArea* area) { _excludes.push_back(area); }
|
||||
|
||||
virtual bool isInside(float x, float y) {
|
||||
for (unsigned int i = 0; i < _includes.size(); ++i)
|
||||
if (_includes[i]->isInside(x, y)) {
|
||||
bool good = true;
|
||||
//@todo: cache _exclude-test results
|
||||
for (unsigned int j = 0; j < _excludes.size(); ++j)
|
||||
if (_excludes[j]->isInside(x, y)) {
|
||||
good = false;
|
||||
break;
|
||||
}
|
||||
if (good) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private:
|
||||
std::vector<IArea*> _includes;
|
||||
std::vector<IArea*> _excludes;
|
||||
};
|
||||
|
||||
|
||||
/// At least one of the areas
|
||||
class OrArea: public IArea
|
||||
{
|
||||
public:
|
||||
OrArea(IArea* a, IArea* b)
|
||||
: _a(a),
|
||||
_b(b)
|
||||
{}
|
||||
|
||||
~OrArea() {
|
||||
if (deleteMe) {
|
||||
if (_a->deleteMe) delete _a;
|
||||
if (_b->deleteMe) delete _b;
|
||||
}
|
||||
}
|
||||
|
||||
virtual bool isInside(float x, float y) {
|
||||
return _a->isInside(x, y) || _b->isInside(x, y);
|
||||
}
|
||||
|
||||
private:
|
||||
IArea* _a;
|
||||
IArea* _b;
|
||||
};
|
||||
|
||||
/// In both areas
|
||||
class AndArea: public IArea
|
||||
{
|
||||
public:
|
||||
AndArea(IArea* a, IArea* b)
|
||||
: _a(a),
|
||||
_b(b)
|
||||
{}
|
||||
|
||||
~AndArea() {
|
||||
if (deleteMe) {
|
||||
if (_a->deleteMe) delete _a;
|
||||
if (_b->deleteMe) delete _b;
|
||||
}
|
||||
}
|
||||
|
||||
virtual bool isInside(float x, float y) {
|
||||
return _a->isInside(x, y) && _b->isInside(x, y);
|
||||
}
|
||||
|
||||
private:
|
||||
IArea* _a;
|
||||
IArea* _b;
|
||||
};
|
||||
|
||||
/// Exactly one of the areas
|
||||
class XorArea: public IArea
|
||||
{
|
||||
public:
|
||||
XorArea(IArea* a, IArea* b)
|
||||
: _a(a),
|
||||
_b(b)
|
||||
{}
|
||||
|
||||
~XorArea() {
|
||||
if (deleteMe) {
|
||||
if (_a->deleteMe) delete _a;
|
||||
if (_b->deleteMe) delete _b;
|
||||
}
|
||||
}
|
||||
|
||||
virtual bool isInside(float x, float y) {
|
||||
return _a->isInside(x, y) ^ _b->isInside(x, y);
|
||||
}
|
||||
|
||||
private:
|
||||
IArea* _a;
|
||||
IArea* _b;
|
||||
};
|
||||
|
||||
/// Everything except this area
|
||||
class NotArea: public IArea
|
||||
{
|
||||
public:
|
||||
NotArea(IArea* a)
|
||||
: _a(a)
|
||||
{}
|
||||
|
||||
~NotArea() {
|
||||
if (deleteMe && _a->deleteMe) delete _a;
|
||||
}
|
||||
|
||||
virtual bool isInside(float x, float y) {
|
||||
return !_a->isInside(x, y);
|
||||
}
|
||||
|
||||
private:
|
||||
IArea* _a;
|
||||
};
|
||||
|
||||
/// First area, but not second
|
||||
/// This is semantically the same as AndArea( a, new NotArea(b) )
|
||||
class DifferenceArea: public IArea
|
||||
{
|
||||
public:
|
||||
DifferenceArea(IArea* a, IArea* b)
|
||||
: _a(a),
|
||||
_b(b)
|
||||
{}
|
||||
|
||||
~DifferenceArea() {
|
||||
if (deleteMe) {
|
||||
if (_a->deleteMe) delete _a;
|
||||
if (_b->deleteMe) delete _b;
|
||||
}
|
||||
}
|
||||
|
||||
virtual bool isInside(float x, float y) {
|
||||
return _a->isInside(x, y) && !_b->isInside(x, y);
|
||||
}
|
||||
private:
|
||||
IArea* _a;
|
||||
IArea* _b;
|
||||
};
|
||||
|
||||
#endif /*NET_MINECRAFT_CLIENT_PLAYER__TouchAreaModel_H__*/
|
||||
#pragma once
|
||||
|
||||
#include "ITouchScreenModel.h"
|
||||
#include <vector>
|
||||
#include "../../../../platform/time.h"
|
||||
|
||||
/// Interface for an area that can be point tested
|
||||
class IArea{
|
||||
public:
|
||||
IArea()
|
||||
: deleteMe(true)
|
||||
{}
|
||||
|
||||
virtual ~IArea() {};
|
||||
virtual bool isInside(float x, float y) = 0;
|
||||
//virtual void expandRectToInclude(float& l, float& t, float& r, float& b) {}
|
||||
|
||||
bool deleteMe;
|
||||
};
|
||||
|
||||
/// Holder for multiple <IArea, int areaId> pairs
|
||||
class TouchAreaModel: public ITouchScreenModel
|
||||
{
|
||||
public:
|
||||
TouchAreaModel() {}
|
||||
|
||||
~TouchAreaModel() {
|
||||
clear();
|
||||
}
|
||||
|
||||
void clear() {
|
||||
for (unsigned int i = 0; i < _areas.size(); ++i) {
|
||||
Area* a = _areas[i];
|
||||
if (a->area && a->area->deleteMe)
|
||||
delete a->area;
|
||||
delete a;
|
||||
}
|
||||
_areas.clear();
|
||||
}
|
||||
|
||||
int getPointerId(const MouseAction& m) {
|
||||
return getPointerId(m.x, m.y, m.pointerId);
|
||||
}
|
||||
|
||||
int getPointerId(int x, int y, int pid) {
|
||||
//static Stopwatch w;
|
||||
//w.printEvery(200, "IArea");
|
||||
//w.start();
|
||||
float fx = (float)x, fy = (float) y;
|
||||
for (unsigned int i = 0; i < _areas.size(); ++i) {
|
||||
const Area* a = _areas[i];
|
||||
if (a->area->isInside(fx, fy)) {
|
||||
//w.stop();
|
||||
return a->areaId;
|
||||
}
|
||||
}
|
||||
//w.stop();
|
||||
return pid;
|
||||
}
|
||||
|
||||
void addArea(int areaId, IArea* area) {
|
||||
Area* a = new Area();
|
||||
a->area = area;
|
||||
a->areaId = areaId;
|
||||
|
||||
_areas.push_back( a );
|
||||
}
|
||||
|
||||
private:
|
||||
struct Area {
|
||||
IArea* area;
|
||||
int areaId;
|
||||
};
|
||||
|
||||
std::vector<Area*> _areas;
|
||||
};
|
||||
|
||||
/// Area represented by a polygon
|
||||
class PolygonArea: public IArea
|
||||
{
|
||||
public:
|
||||
PolygonArea(int numPoints, const float* xp, const float* yp)
|
||||
: _numPoints(numPoints)
|
||||
{
|
||||
_x = new float[numPoints];
|
||||
_y = new float[numPoints];
|
||||
|
||||
for (int i = 0; i < numPoints; ++i) {
|
||||
_x[i] = xp[i];
|
||||
_y[i] = yp[i];
|
||||
}
|
||||
}
|
||||
|
||||
~PolygonArea() {
|
||||
delete[] _x;
|
||||
delete[] _y;
|
||||
}
|
||||
|
||||
virtual bool isInside(float x, float y)
|
||||
{
|
||||
bool c = false;
|
||||
for (int i = 0, j = _numPoints-1; i < _numPoints; j = i++) {
|
||||
if ((((_y[i] <= y) && (y < _y[j])) ||
|
||||
((_y[j] <= y) && (y < _y[i]))) &&
|
||||
(x < (_x[j] - _x[i]) * (y - _y[i]) / (_y[j] - _y[i]) + _x[i]))
|
||||
c = !c;
|
||||
}
|
||||
return c == 1;
|
||||
}
|
||||
|
||||
//private:
|
||||
float* _x;
|
||||
float* _y;
|
||||
int _numPoints;
|
||||
};
|
||||
|
||||
/// Area represented by a rectangle
|
||||
class RectangleArea: public IArea
|
||||
{
|
||||
public:
|
||||
RectangleArea(float x0, float y0, float x1, float y1)
|
||||
: _x0(x0),
|
||||
_x1(x1),
|
||||
_y0(y0),
|
||||
_y1(y1)
|
||||
{}
|
||||
|
||||
virtual bool isInside(float x, float y) {
|
||||
return x >= _x0 && x <= _x1
|
||||
&& y >= _y0 && y <= _y1;
|
||||
}
|
||||
|
||||
virtual float centerX()
|
||||
{
|
||||
return _x0 + (_x1 - _x0) * .5f;
|
||||
}
|
||||
|
||||
virtual float centerY()
|
||||
{
|
||||
return _y0 + (_y1 - _y0) * .5f;
|
||||
}
|
||||
|
||||
//private:
|
||||
float _x0, _x1;
|
||||
float _y0, _y1;
|
||||
};
|
||||
|
||||
/// An area represented by a circle
|
||||
class CircleArea: public IArea
|
||||
{
|
||||
public:
|
||||
CircleArea(float x, float y, float r)
|
||||
: _x(x), _y(y), _rr(r*r)
|
||||
{}
|
||||
|
||||
virtual bool isInside(float x, float y) {
|
||||
const float dx = x - _x;
|
||||
const float dy = y - _y;
|
||||
return (dx*dx + dy*dy) <= _rr;
|
||||
}
|
||||
|
||||
private:
|
||||
float _x, _y;
|
||||
float _rr;
|
||||
};
|
||||
|
||||
/// Inside any area in include list but none of exclude list
|
||||
class IncludeExcludeArea: public IArea
|
||||
{
|
||||
public:
|
||||
IncludeExcludeArea() {}
|
||||
|
||||
~IncludeExcludeArea() {
|
||||
clear();
|
||||
}
|
||||
|
||||
void clear() {
|
||||
if (deleteMe) {
|
||||
for (unsigned int i = 0; i < _includes.size(); ++i) {
|
||||
IArea* area = _includes[i];
|
||||
if (area->deleteMe) delete area;
|
||||
}
|
||||
for (unsigned int i = 0; i < _excludes.size(); ++i) {
|
||||
IArea* area = _excludes[i];
|
||||
if (area->deleteMe) delete area;
|
||||
}
|
||||
}
|
||||
_includes.clear();
|
||||
_excludes.clear();
|
||||
}
|
||||
|
||||
void include(IArea* area) { _includes.push_back(area); }
|
||||
void exclude(IArea* area) { _excludes.push_back(area); }
|
||||
|
||||
virtual bool isInside(float x, float y) {
|
||||
for (unsigned int i = 0; i < _includes.size(); ++i)
|
||||
if (_includes[i]->isInside(x, y)) {
|
||||
bool good = true;
|
||||
//@todo: cache _exclude-test results
|
||||
for (unsigned int j = 0; j < _excludes.size(); ++j)
|
||||
if (_excludes[j]->isInside(x, y)) {
|
||||
good = false;
|
||||
break;
|
||||
}
|
||||
if (good) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private:
|
||||
std::vector<IArea*> _includes;
|
||||
std::vector<IArea*> _excludes;
|
||||
};
|
||||
|
||||
|
||||
/// At least one of the areas
|
||||
class OrArea: public IArea
|
||||
{
|
||||
public:
|
||||
OrArea(IArea* a, IArea* b)
|
||||
: _a(a),
|
||||
_b(b)
|
||||
{}
|
||||
|
||||
~OrArea() {
|
||||
if (deleteMe) {
|
||||
if (_a->deleteMe) delete _a;
|
||||
if (_b->deleteMe) delete _b;
|
||||
}
|
||||
}
|
||||
|
||||
virtual bool isInside(float x, float y) {
|
||||
return _a->isInside(x, y) || _b->isInside(x, y);
|
||||
}
|
||||
|
||||
private:
|
||||
IArea* _a;
|
||||
IArea* _b;
|
||||
};
|
||||
|
||||
/// In both areas
|
||||
class AndArea: public IArea
|
||||
{
|
||||
public:
|
||||
AndArea(IArea* a, IArea* b)
|
||||
: _a(a),
|
||||
_b(b)
|
||||
{}
|
||||
|
||||
~AndArea() {
|
||||
if (deleteMe) {
|
||||
if (_a->deleteMe) delete _a;
|
||||
if (_b->deleteMe) delete _b;
|
||||
}
|
||||
}
|
||||
|
||||
virtual bool isInside(float x, float y) {
|
||||
return _a->isInside(x, y) && _b->isInside(x, y);
|
||||
}
|
||||
|
||||
private:
|
||||
IArea* _a;
|
||||
IArea* _b;
|
||||
};
|
||||
|
||||
/// Exactly one of the areas
|
||||
class XorArea: public IArea
|
||||
{
|
||||
public:
|
||||
XorArea(IArea* a, IArea* b)
|
||||
: _a(a),
|
||||
_b(b)
|
||||
{}
|
||||
|
||||
~XorArea() {
|
||||
if (deleteMe) {
|
||||
if (_a->deleteMe) delete _a;
|
||||
if (_b->deleteMe) delete _b;
|
||||
}
|
||||
}
|
||||
|
||||
virtual bool isInside(float x, float y) {
|
||||
return _a->isInside(x, y) ^ _b->isInside(x, y);
|
||||
}
|
||||
|
||||
private:
|
||||
IArea* _a;
|
||||
IArea* _b;
|
||||
};
|
||||
|
||||
/// Everything except this area
|
||||
class NotArea: public IArea
|
||||
{
|
||||
public:
|
||||
NotArea(IArea* a)
|
||||
: _a(a)
|
||||
{}
|
||||
|
||||
~NotArea() {
|
||||
if (deleteMe && _a->deleteMe) delete _a;
|
||||
}
|
||||
|
||||
virtual bool isInside(float x, float y) {
|
||||
return !_a->isInside(x, y);
|
||||
}
|
||||
|
||||
private:
|
||||
IArea* _a;
|
||||
};
|
||||
|
||||
/// First area, but not second
|
||||
/// This is semantically the same as AndArea( a, new NotArea(b) )
|
||||
class DifferenceArea: public IArea
|
||||
{
|
||||
public:
|
||||
DifferenceArea(IArea* a, IArea* b)
|
||||
: _a(a),
|
||||
_b(b)
|
||||
{}
|
||||
|
||||
~DifferenceArea() {
|
||||
if (deleteMe) {
|
||||
if (_a->deleteMe) delete _a;
|
||||
if (_b->deleteMe) delete _b;
|
||||
}
|
||||
}
|
||||
|
||||
virtual bool isInside(float x, float y) {
|
||||
return _a->isInside(x, y) && !_b->isInside(x, y);
|
||||
}
|
||||
private:
|
||||
IArea* _a;
|
||||
IArea* _b;
|
||||
};
|
||||
|
||||
|
||||
@@ -1,471 +1,469 @@
|
||||
#ifndef NET_MINECRAFT_CLIENT_PLAYER_INPUT_TOUCHSCREEN_TouchInputHolder_H__
|
||||
#define NET_MINECRAFT_CLIENT_PLAYER_INPUT_TOUCHSCREEN_TouchInputHolder_H__
|
||||
|
||||
#include "../IInputHolder.h"
|
||||
#include "TouchscreenInput.h"
|
||||
|
||||
#include "../ITurnInput.h"
|
||||
#include "TouchAreaModel.h"
|
||||
#include "../../../../platform/input/Multitouch.h"
|
||||
#include "../../../../platform/time.h"
|
||||
#include "../../../../util/SmoothFloat.h"
|
||||
|
||||
#include "../../../../world/entity/player/Player.h"
|
||||
#include "../../../../world/entity/player/Inventory.h"
|
||||
|
||||
template <class T>
|
||||
class ModifyNotify {
|
||||
public:
|
||||
ModifyNotify()
|
||||
: _changed(false)
|
||||
{}
|
||||
|
||||
T& getOld() { return _old; }
|
||||
T& getNew() { return _new; }
|
||||
|
||||
bool update(T& val) {
|
||||
_changed = !equals(val);
|
||||
if (_changed) {
|
||||
_old = _new;
|
||||
_new = val;
|
||||
}
|
||||
return _changed;
|
||||
}
|
||||
|
||||
bool hasChanged() const { return _changed; }
|
||||
|
||||
virtual bool equals(const T& newVal) {
|
||||
return _old != newVal;
|
||||
}
|
||||
protected:
|
||||
T _old;
|
||||
private:
|
||||
T _new;
|
||||
bool _changed;
|
||||
};
|
||||
|
||||
//
|
||||
// Implementation for unified [Turn & Build Input]
|
||||
//
|
||||
class UnifiedTurnBuild: public GuiComponent,
|
||||
public ITurnInput,
|
||||
public IBuildInput
|
||||
{
|
||||
public:
|
||||
static const int MODE_OFFSET = 1;
|
||||
static const int MODE_DELTA = 2;
|
||||
|
||||
UnifiedTurnBuild(int turnMode, int width, int height, float maxMovementDelta, float sensitivity, IInputHolder* holder, Minecraft* minecraft)
|
||||
: mode(turnMode),
|
||||
_holder(holder),
|
||||
_options(&minecraft->options),
|
||||
cxO(0), cyO(0),
|
||||
wasActive(false),
|
||||
_totalMoveDelta(0),
|
||||
_maxMovement(maxMovementDelta),
|
||||
_lastPlayer(0),
|
||||
screenArea(-1, -1, 0, 0),
|
||||
allowPicking(false),
|
||||
state(State_None),
|
||||
moveArea(-1,-1,0,0),
|
||||
joyTouchArea(-1, -1, 0, 0),
|
||||
inventoryArea(-1,-1, 0, 0),
|
||||
pauseArea(-1, -1, 0, 0),
|
||||
_buildMovement(0),
|
||||
_sentFirstRemove(false),
|
||||
_canDestroy(false),
|
||||
_forceCanUse(false)
|
||||
{
|
||||
_area.deleteMe = false;
|
||||
setSensitivity(sensitivity);
|
||||
//((ITurnInput*)this)->onConfigChanged(createConfig(minecraft));
|
||||
onConfigChanged(createConfig(minecraft));
|
||||
|
||||
_lastBuildDownTime = _startTurnTime = getTimeS();
|
||||
}
|
||||
|
||||
void setSensitivity(float sensitivity) {
|
||||
_sensitivity = sensitivity;
|
||||
}
|
||||
|
||||
virtual void onConfigChanged(const Config& c) {
|
||||
if (false && _options->getBooleanValue(OPTIONS_IS_JOY_TOUCH_AREA)) {
|
||||
int touchWidth = c.width - (int)inventoryArea._x1;
|
||||
if (touchWidth > (int)c.minecraft->pixelCalc.millimetersToPixels(60))
|
||||
touchWidth = (int)c.minecraft->pixelCalc.millimetersToPixels(60);
|
||||
|
||||
int touchHeight = (int)(c.height * 0.4f);
|
||||
if (touchHeight > (int)c.minecraft->pixelCalc.millimetersToPixels(40))
|
||||
touchHeight = (int)c.minecraft->pixelCalc.millimetersToPixels(40);
|
||||
|
||||
joyTouchArea._x0 = (float)(c.width - touchWidth);
|
||||
joyTouchArea._y0 = (float)(c.height - touchHeight);
|
||||
joyTouchArea._x1 = (float)c.width;
|
||||
joyTouchArea._y1 = (float)c.height;
|
||||
|
||||
_area.clear();
|
||||
_area.include (&joyTouchArea);
|
||||
_model.clear();
|
||||
_model.addArea(AREA_TURN, &_area);
|
||||
} else {
|
||||
screenArea = RectangleArea(0, 0, (float)c.width, (float)c.height);
|
||||
// Expand the move area a bit
|
||||
const float border = 10;
|
||||
const float widen = (moveArea._x1-moveArea._x0) * 0.05f + border; // ~5% wider
|
||||
moveArea._x0 -= widen;
|
||||
moveArea._x1 += widen;
|
||||
const float heighten = (moveArea._y1-moveArea._y0) * 0.05f + border; // ~5% taller
|
||||
moveArea._y0 -= heighten;
|
||||
moveArea._y1 += heighten;
|
||||
|
||||
pauseArea._x0 -= border;
|
||||
pauseArea._x1 += border;
|
||||
pauseArea._y0 -= border;
|
||||
pauseArea._y1 += border;
|
||||
|
||||
//LOGI("move: %f, %f, %f, %f\n", moveArea._x0, moveArea._y0, moveArea._x1, moveArea._y1);
|
||||
|
||||
_area.clear();
|
||||
_area.include(&screenArea);
|
||||
_area.exclude(&moveArea);
|
||||
_area.exclude(&inventoryArea);
|
||||
#ifdef __APPLE__
|
||||
_area.exclude(&pauseArea);
|
||||
#endif /*__APPLE__*/
|
||||
//LOGI("Movearea: %f %f %f% f\n", moveArea._x0, moveArea._x1, moveArea._y0, moveArea._y1);
|
||||
|
||||
_model.clear();
|
||||
_model.addArea(AREA_TURN, &_area);
|
||||
}
|
||||
}
|
||||
|
||||
float calcNewAlpha(float current, float wanted) {
|
||||
if (wanted > current)
|
||||
return Mth::clamp(current + 0.02f, 0.0f, wanted);
|
||||
if (wanted < current)
|
||||
return Mth::clamp(current - 0.04f, wanted, 1.0f);
|
||||
return current;
|
||||
}
|
||||
|
||||
//
|
||||
// Implementation for the ITurnInput part
|
||||
//
|
||||
TurnDelta getTurnDelta() {
|
||||
float dx = 0, dy = 0;
|
||||
const float now = getTimeS();
|
||||
|
||||
float cx = 0;
|
||||
float cy = 0;
|
||||
bool isActive = false;
|
||||
|
||||
const int* pointerIds;
|
||||
bool wasFirstMovement = false;
|
||||
int pointerCount = Multitouch::getActivePointerIds(&pointerIds);
|
||||
for (int i = 0; i < pointerCount; ++i) {
|
||||
int p = pointerIds[i];
|
||||
int x = Multitouch::getX(p);
|
||||
int y = Multitouch::getY(p);
|
||||
int areaId = _model.getPointerId(x, y, p);
|
||||
|
||||
if (areaId == AREA_TURN) {
|
||||
isActive = true;
|
||||
cx = (float)x * 0.5f;
|
||||
cy = (float)y * -0.5f;
|
||||
wasFirstMovement = Multitouch::wasFirstMovement(p);
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (isActive && !wasActive) {
|
||||
_startTurnTime = now;
|
||||
_totalMoveDelta = 0;
|
||||
bool isInMovement = _lastPlayer? getSpeedSquared(_lastPlayer) > 0.01f/*.25f*/ : false;
|
||||
//state = isInMovement? State_Turn : State_Deciding;
|
||||
state = State_Deciding;
|
||||
_canDestroy = !isInMovement;
|
||||
_forceCanUse = false;
|
||||
if (!_canDestroy && (_lastPlayer && _lastPlayer->canUseCarriedItemWhileMoving())) {
|
||||
_forceCanUse = true;
|
||||
_canDestroy = true;
|
||||
}
|
||||
_sentFirstRemove = false;
|
||||
} else if (wasActive && !isActive) {
|
||||
_sentFirstRemove = false;
|
||||
state = State_None;
|
||||
//_inBuild = false;
|
||||
}
|
||||
|
||||
if (MODE_DELTA == mode && (wasActive || isActive)) {
|
||||
// const float dt = getDeltaTime();
|
||||
// const float MaxTurnX = 100.0f;
|
||||
// const float MaxTurnY = 100.0f;
|
||||
const float DeadZone = 0;//0.25f * dt;//0.02f;
|
||||
|
||||
if (!wasActive) {
|
||||
cxO = cx;
|
||||
cyO = cy;
|
||||
}
|
||||
if (isActive) {
|
||||
dx = _sensitivity * linearTransform(cx - cxO, DeadZone);// * MaxTurnX;
|
||||
dy = _sensitivity * linearTransform(cy - cyO, DeadZone);// * MaxTurnY;
|
||||
|
||||
float moveDelta = ( Mth::abs(dx) + Mth::abs(dy) );
|
||||
//LOGI("moveDelta is : %f\n", moveDelta);
|
||||
|
||||
if (moveDelta > _maxMovement) {
|
||||
dx = 0;
|
||||
dy = 0;
|
||||
moveDelta = 0;
|
||||
}
|
||||
_totalMoveDelta += moveDelta;
|
||||
|
||||
if (state == State_Deciding && _totalMoveDelta >= MaxBuildMovement/* && !_forceCanUse*/)
|
||||
state = State_Turn;
|
||||
|
||||
// If a certain time has passed since we pressed button; check if
|
||||
// we've moved enough to prevent removal state to become activated
|
||||
const float since = now - _startTurnTime;
|
||||
if (state == State_Deciding && (since >= (0.001f*RemovalMilliseconds))) {
|
||||
//LOGI("DECIDED!: %f\n", _totalMoveDelta);
|
||||
bool isInMovement = _lastPlayer? getSpeedSquared(_lastPlayer) > 0.01f/*.25f*/ : false;
|
||||
if (!_forceCanUse && (_totalMoveDelta > 20.0f || isInMovement)) {
|
||||
state = State_Turn;
|
||||
} else {
|
||||
state = State_Destroy;
|
||||
_canDestroy = true;
|
||||
}
|
||||
}
|
||||
|
||||
// Removing the pointer ketchup-effect that's built into some devices
|
||||
if (wasFirstMovement) {
|
||||
dx = dy = 0;
|
||||
}
|
||||
|
||||
cxO = cx;
|
||||
cyO = cy;
|
||||
//LOGI("move delta: %f (%f, %f), %d\n", moveDelta, dx, dy, state);
|
||||
}
|
||||
} else {
|
||||
// Wasn't active, and isn't active!
|
||||
state = State_None;
|
||||
}
|
||||
|
||||
updateFeedbackProgressAlpha(now);
|
||||
|
||||
wasActive = isActive;
|
||||
return TurnDelta(dx, -dy);
|
||||
}
|
||||
|
||||
void updateFeedbackProgressAlpha(float now) {
|
||||
const float MinAlphaValue = -0.05f;
|
||||
if (_canDestroy) {
|
||||
// Hack to test out fading in feedback circle
|
||||
const float since = now - _startTurnTime;
|
||||
if (state == State_Deciding) {
|
||||
const float wantedAlpha = since / (0.001f*RemovalMilliseconds);
|
||||
_holder->alpha = wantedAlpha * wantedAlpha;
|
||||
} else {
|
||||
if (state == State_Destroy) {
|
||||
_holder->alpha = calcNewAlpha(_holder->alpha, 1);
|
||||
} else if (state == State_Turn || state == State_None) {
|
||||
_holder->alpha = calcNewAlpha(_holder->alpha, 0);
|
||||
}
|
||||
|
||||
}
|
||||
} else {
|
||||
_holder->alpha = MinAlphaValue;
|
||||
}
|
||||
//LOGI("state: %d, canDestroy: %d %d\n", state, _canDestroy, _forceCanUse);
|
||||
//LOGI("alpha: %f\n", _holder->alpha);
|
||||
}
|
||||
|
||||
bool isInsideArea(float x, float y) {
|
||||
return _area.isInside(x, y);
|
||||
}
|
||||
|
||||
int mode;
|
||||
|
||||
static float getSpeedSquared(Entity* m) {
|
||||
const float xd = m->x - m->xo;
|
||||
const float yd = m->y - m->yo;
|
||||
const float zd = m->z - m->zo;
|
||||
const float speedSquared = xd*xd + yd*yd + zd*zd;
|
||||
return speedSquared;
|
||||
}
|
||||
|
||||
void render(float alpha) {
|
||||
if (_options->getBooleanValue(OPTIONS_IS_JOY_TOUCH_AREA)) {
|
||||
fill( (int) (Gui::InvGuiScale * joyTouchArea._x0),
|
||||
(int) (Gui::InvGuiScale * joyTouchArea._y0),
|
||||
(int) (Gui::InvGuiScale * joyTouchArea._x1),
|
||||
(int) (Gui::InvGuiScale * joyTouchArea._y1), 0x40000000);//0x20ffffff);
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// Implementation for the IBuildInput part
|
||||
//
|
||||
virtual bool tickBuild(Player* player, BuildActionIntention* bai) {
|
||||
_lastPlayer = player;
|
||||
|
||||
if (state == State_Destroy) {
|
||||
if (!_sentFirstRemove) {
|
||||
*bai = BuildActionIntention((_forceCanUse?0:BuildActionIntention::BAI_FIRSTREMOVE) | BuildActionIntention::BAI_INTERACT);
|
||||
_sentFirstRemove = true;
|
||||
} else {
|
||||
*bai = BuildActionIntention((_forceCanUse?0:BuildActionIntention::BAI_REMOVE) | BuildActionIntention::BAI_INTERACT);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
// Rewind the queue, in case someone has used it up before
|
||||
Multitouch::rewind();
|
||||
const float now = getTimeS();
|
||||
allowPicking = false;
|
||||
bool handled = false;
|
||||
|
||||
while (Multitouch::next()) {
|
||||
MouseAction& m = Multitouch::getEvent();
|
||||
if (m.action == MouseAction::ACTION_MOVE) continue;
|
||||
|
||||
int areaId = _model.getPointerId(m.x, m.y, m.pointerId);
|
||||
if (areaId != AREA_TURN) continue;
|
||||
|
||||
allowPicking = true;
|
||||
//LOGI("down? %d, up? %d (%d, %d)\n", z && (m.data == MouseAction::DATA_DOWN), z && (m.data == MouseAction::DATA_UP), m.x, m.y);
|
||||
|
||||
if (_totalMoveDelta <= MaxBuildMovement && (m.data == MouseAction::DATA_UP && !handled)) {
|
||||
const float since = now - _lastBuildDownTime;
|
||||
//LOGI("move: (%d) %.2f - %f\n", state, _totalMoveDelta, since);
|
||||
if (state <= State_Deciding) {
|
||||
if (since >= 0.0f && since < 0.25f) {
|
||||
// We've pressed and released in haste; Let's build!
|
||||
*bai = BuildActionIntention(BuildActionIntention::BAI_BUILD | BuildActionIntention::BAI_ATTACK);
|
||||
handled = true;
|
||||
}
|
||||
}
|
||||
state = State_None;
|
||||
} else if (m.data == MouseAction::DATA_DOWN) {
|
||||
_lastBuildDownTime = now;
|
||||
_buildMovement = 0;
|
||||
state = State_Deciding;
|
||||
}
|
||||
}
|
||||
return handled;
|
||||
}
|
||||
|
||||
bool allowPicking;
|
||||
float alpha;
|
||||
SmoothFloat smoothAlpha;
|
||||
|
||||
RectangleArea screenArea;
|
||||
RectangleArea moveArea;
|
||||
RectangleArea joyTouchArea;
|
||||
RectangleArea inventoryArea;
|
||||
RectangleArea pauseArea;
|
||||
|
||||
private:
|
||||
IInputHolder* _holder;
|
||||
|
||||
// Turn
|
||||
int cid;
|
||||
float cxO, cyO;
|
||||
bool wasActive;
|
||||
|
||||
TouchAreaModel _model;
|
||||
IncludeExcludeArea _area;
|
||||
|
||||
bool _decidedTurnMode;
|
||||
|
||||
float _startTurnTime;
|
||||
float _totalMoveDelta;
|
||||
float _maxMovement;
|
||||
float _sensitivity;
|
||||
|
||||
Player* _lastPlayer;
|
||||
|
||||
// Build
|
||||
float _lastBuildDownTime;
|
||||
float _buildMovement;
|
||||
bool _sentFirstRemove;
|
||||
bool _canDestroy;
|
||||
bool _forceCanUse;
|
||||
|
||||
int state;
|
||||
static const int State_None = 0;
|
||||
static const int State_Deciding = 1;
|
||||
static const int State_Turn = 2;
|
||||
static const int State_Destroy = 3;
|
||||
static const int State_Build = 4; // Will never happen
|
||||
|
||||
static const int MaxBuildMovement = 20;
|
||||
static const int RemovalMilliseconds = 400;
|
||||
|
||||
static const int AREA_TURN = 100;
|
||||
Options* _options;
|
||||
};
|
||||
|
||||
class Minecraft;
|
||||
|
||||
#if defined(_MSC_VER)
|
||||
#pragma warning( disable : 4355 ) // 'this' pointer in initialization list which is perfectly legal
|
||||
#endif
|
||||
|
||||
class TouchInputHolder: public IInputHolder
|
||||
{
|
||||
public:
|
||||
TouchInputHolder(Minecraft* mc, Options* options)
|
||||
: _mc(mc),
|
||||
_move(mc, options),
|
||||
_turnBuild(UnifiedTurnBuild::MODE_DELTA, mc->width, mc->height, (float)MovementLimit, 1, this, mc)
|
||||
{
|
||||
onConfigChanged(createConfig(mc));
|
||||
}
|
||||
~TouchInputHolder() {
|
||||
}
|
||||
|
||||
virtual void onConfigChanged(const Config& c) {
|
||||
_move.onConfigChanged(c);
|
||||
_turnBuild.moveArea = _move.getRectangleArea();
|
||||
_turnBuild.pauseArea = _move.getPauseRectangleArea();
|
||||
_turnBuild.inventoryArea = _mc->gui.getRectangleArea( _mc->options.getBooleanValue(OPTIONS_IS_LEFT_HANDED)? 1 : -1 );
|
||||
_turnBuild.setSensitivity(c.options->getBooleanValue(OPTIONS_IS_JOY_TOUCH_AREA)? 1.8f : 1.0f);
|
||||
((ITurnInput*)&_turnBuild)->onConfigChanged(c);
|
||||
}
|
||||
|
||||
virtual bool allowPicking() {
|
||||
const int* pointerIds;
|
||||
int pointerCount = Multitouch::getActivePointerIds(&pointerIds);
|
||||
for (int i = 0; i < pointerCount; ++i) {
|
||||
int p = pointerIds[i];
|
||||
const float x = Multitouch::getX(p);
|
||||
const float y = Multitouch::getY(p);
|
||||
|
||||
if (_turnBuild.isInsideArea(x, y)) {
|
||||
mousex = x;
|
||||
mousey = y;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
// return _turnBuild.allowPicking;
|
||||
}
|
||||
|
||||
virtual void render(float alpha) {
|
||||
_turnBuild.render(alpha);
|
||||
}
|
||||
|
||||
virtual IMoveInput* getMoveInput() { return &_move; }
|
||||
virtual ITurnInput* getTurnInput() { return &_turnBuild; }
|
||||
virtual IBuildInput* getBuildInput() { return &_turnBuild; }
|
||||
|
||||
private:
|
||||
TouchscreenInput_TestFps _move;
|
||||
UnifiedTurnBuild _turnBuild;
|
||||
|
||||
Minecraft* _mc;
|
||||
|
||||
static const int MovementLimit = 200; // per update
|
||||
};
|
||||
|
||||
#endif /*NET_MINECRAFT_CLIENT_PLAYER_INPUT_TOUCHSCREEN_TouchInputHolder_H__*/
|
||||
#pragma once
|
||||
|
||||
#include "../IInputHolder.h"
|
||||
#include "TouchscreenInput.h"
|
||||
|
||||
#include "../ITurnInput.h"
|
||||
#include "TouchAreaModel.h"
|
||||
#include "../../../../platform/input/Multitouch.h"
|
||||
#include "../../../../platform/time.h"
|
||||
#include "../../../../util/SmoothFloat.h"
|
||||
|
||||
#include "../../../../world/entity/player/Player.h"
|
||||
#include "../../../../world/entity/player/Inventory.h"
|
||||
|
||||
template <class T>
|
||||
class ModifyNotify {
|
||||
public:
|
||||
ModifyNotify()
|
||||
: _changed(false)
|
||||
{}
|
||||
|
||||
T& getOld() { return _old; }
|
||||
T& getNew() { return _new; }
|
||||
|
||||
bool update(T& val) {
|
||||
_changed = !equals(val);
|
||||
if (_changed) {
|
||||
_old = _new;
|
||||
_new = val;
|
||||
}
|
||||
return _changed;
|
||||
}
|
||||
|
||||
bool hasChanged() const { return _changed; }
|
||||
|
||||
virtual bool equals(const T& newVal) {
|
||||
return _old != newVal;
|
||||
}
|
||||
protected:
|
||||
T _old;
|
||||
private:
|
||||
T _new;
|
||||
bool _changed;
|
||||
};
|
||||
|
||||
//
|
||||
// Implementation for unified [Turn & Build Input]
|
||||
//
|
||||
class UnifiedTurnBuild: public GuiComponent,
|
||||
public ITurnInput,
|
||||
public IBuildInput
|
||||
{
|
||||
public:
|
||||
static const int MODE_OFFSET = 1;
|
||||
static const int MODE_DELTA = 2;
|
||||
|
||||
UnifiedTurnBuild(int turnMode, int width, int height, float maxMovementDelta, float sensitivity, IInputHolder* holder, Minecraft* minecraft)
|
||||
: mode(turnMode),
|
||||
_holder(holder),
|
||||
_options(&minecraft->options),
|
||||
cxO(0), cyO(0),
|
||||
wasActive(false),
|
||||
_totalMoveDelta(0),
|
||||
_maxMovement(maxMovementDelta),
|
||||
_lastPlayer(0),
|
||||
screenArea(-1, -1, 0, 0),
|
||||
allowPicking(false),
|
||||
state(State_None),
|
||||
moveArea(-1,-1,0,0),
|
||||
joyTouchArea(-1, -1, 0, 0),
|
||||
inventoryArea(-1,-1, 0, 0),
|
||||
pauseArea(-1, -1, 0, 0),
|
||||
_buildMovement(0),
|
||||
_sentFirstRemove(false),
|
||||
_canDestroy(false),
|
||||
_forceCanUse(false)
|
||||
{
|
||||
_area.deleteMe = false;
|
||||
setSensitivity(sensitivity);
|
||||
//((ITurnInput*)this)->onConfigChanged(createConfig(minecraft));
|
||||
onConfigChanged(createConfig(minecraft));
|
||||
|
||||
_lastBuildDownTime = _startTurnTime = getTimeS();
|
||||
}
|
||||
|
||||
void setSensitivity(float sensitivity) {
|
||||
_sensitivity = sensitivity;
|
||||
}
|
||||
|
||||
virtual void onConfigChanged(const Config& c) {
|
||||
if (false && _options->getBooleanValue(OPTIONS_IS_JOY_TOUCH_AREA)) {
|
||||
int touchWidth = c.width - (int)inventoryArea._x1;
|
||||
if (touchWidth > (int)c.minecraft->pixelCalc.millimetersToPixels(60))
|
||||
touchWidth = (int)c.minecraft->pixelCalc.millimetersToPixels(60);
|
||||
|
||||
int touchHeight = (int)(c.height * 0.4f);
|
||||
if (touchHeight > (int)c.minecraft->pixelCalc.millimetersToPixels(40))
|
||||
touchHeight = (int)c.minecraft->pixelCalc.millimetersToPixels(40);
|
||||
|
||||
joyTouchArea._x0 = (float)(c.width - touchWidth);
|
||||
joyTouchArea._y0 = (float)(c.height - touchHeight);
|
||||
joyTouchArea._x1 = (float)c.width;
|
||||
joyTouchArea._y1 = (float)c.height;
|
||||
|
||||
_area.clear();
|
||||
_area.include (&joyTouchArea);
|
||||
_model.clear();
|
||||
_model.addArea(AREA_TURN, &_area);
|
||||
} else {
|
||||
screenArea = RectangleArea(0, 0, (float)c.width, (float)c.height);
|
||||
// Expand the move area a bit
|
||||
const float border = 10;
|
||||
const float widen = (moveArea._x1-moveArea._x0) * 0.05f + border; // ~5% wider
|
||||
moveArea._x0 -= widen;
|
||||
moveArea._x1 += widen;
|
||||
const float heighten = (moveArea._y1-moveArea._y0) * 0.05f + border; // ~5% taller
|
||||
moveArea._y0 -= heighten;
|
||||
moveArea._y1 += heighten;
|
||||
|
||||
pauseArea._x0 -= border;
|
||||
pauseArea._x1 += border;
|
||||
pauseArea._y0 -= border;
|
||||
pauseArea._y1 += border;
|
||||
|
||||
//LOGI("move: %f, %f, %f, %f\n", moveArea._x0, moveArea._y0, moveArea._x1, moveArea._y1);
|
||||
|
||||
_area.clear();
|
||||
_area.include(&screenArea);
|
||||
_area.exclude(&moveArea);
|
||||
_area.exclude(&inventoryArea);
|
||||
#ifdef __APPLE__
|
||||
_area.exclude(&pauseArea);
|
||||
#endif /*__APPLE__*/
|
||||
//LOGI("Movearea: %f %f %f% f\n", moveArea._x0, moveArea._x1, moveArea._y0, moveArea._y1);
|
||||
|
||||
_model.clear();
|
||||
_model.addArea(AREA_TURN, &_area);
|
||||
}
|
||||
}
|
||||
|
||||
float calcNewAlpha(float current, float wanted) {
|
||||
if (wanted > current)
|
||||
return Mth::clamp(current + 0.02f, 0.0f, wanted);
|
||||
if (wanted < current)
|
||||
return Mth::clamp(current - 0.04f, wanted, 1.0f);
|
||||
return current;
|
||||
}
|
||||
|
||||
//
|
||||
// Implementation for the ITurnInput part
|
||||
//
|
||||
TurnDelta getTurnDelta() {
|
||||
float dx = 0, dy = 0;
|
||||
const float now = getTimeS();
|
||||
|
||||
float cx = 0;
|
||||
float cy = 0;
|
||||
bool isActive = false;
|
||||
|
||||
const int* pointerIds;
|
||||
bool wasFirstMovement = false;
|
||||
int pointerCount = Multitouch::getActivePointerIds(&pointerIds);
|
||||
for (int i = 0; i < pointerCount; ++i) {
|
||||
int p = pointerIds[i];
|
||||
int x = Multitouch::getX(p);
|
||||
int y = Multitouch::getY(p);
|
||||
int areaId = _model.getPointerId(x, y, p);
|
||||
|
||||
if (areaId == AREA_TURN) {
|
||||
isActive = true;
|
||||
cx = (float)x * 0.5f;
|
||||
cy = (float)y * -0.5f;
|
||||
wasFirstMovement = Multitouch::wasFirstMovement(p);
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (isActive && !wasActive) {
|
||||
_startTurnTime = now;
|
||||
_totalMoveDelta = 0;
|
||||
bool isInMovement = _lastPlayer? getSpeedSquared(_lastPlayer) > 0.01f/*.25f*/ : false;
|
||||
//state = isInMovement? State_Turn : State_Deciding;
|
||||
state = State_Deciding;
|
||||
_canDestroy = !isInMovement;
|
||||
_forceCanUse = false;
|
||||
if (!_canDestroy && (_lastPlayer && _lastPlayer->canUseCarriedItemWhileMoving())) {
|
||||
_forceCanUse = true;
|
||||
_canDestroy = true;
|
||||
}
|
||||
_sentFirstRemove = false;
|
||||
} else if (wasActive && !isActive) {
|
||||
_sentFirstRemove = false;
|
||||
state = State_None;
|
||||
//_inBuild = false;
|
||||
}
|
||||
|
||||
if (MODE_DELTA == mode && (wasActive || isActive)) {
|
||||
// const float dt = getDeltaTime();
|
||||
// const float MaxTurnX = 100.0f;
|
||||
// const float MaxTurnY = 100.0f;
|
||||
const float DeadZone = 0;//0.25f * dt;//0.02f;
|
||||
|
||||
if (!wasActive) {
|
||||
cxO = cx;
|
||||
cyO = cy;
|
||||
}
|
||||
if (isActive) {
|
||||
dx = _sensitivity * linearTransform(cx - cxO, DeadZone);// * MaxTurnX;
|
||||
dy = _sensitivity * linearTransform(cy - cyO, DeadZone);// * MaxTurnY;
|
||||
|
||||
float moveDelta = ( Mth::abs(dx) + Mth::abs(dy) );
|
||||
//LOGI("moveDelta is : %f\n", moveDelta);
|
||||
|
||||
if (moveDelta > _maxMovement) {
|
||||
dx = 0;
|
||||
dy = 0;
|
||||
moveDelta = 0;
|
||||
}
|
||||
_totalMoveDelta += moveDelta;
|
||||
|
||||
if (state == State_Deciding && _totalMoveDelta >= MaxBuildMovement/* && !_forceCanUse*/)
|
||||
state = State_Turn;
|
||||
|
||||
// If a certain time has passed since we pressed button; check if
|
||||
// we've moved enough to prevent removal state to become activated
|
||||
const float since = now - _startTurnTime;
|
||||
if (state == State_Deciding && (since >= (0.001f*RemovalMilliseconds))) {
|
||||
//LOGI("DECIDED!: %f\n", _totalMoveDelta);
|
||||
bool isInMovement = _lastPlayer? getSpeedSquared(_lastPlayer) > 0.01f/*.25f*/ : false;
|
||||
if (!_forceCanUse && (_totalMoveDelta > 20.0f || isInMovement)) {
|
||||
state = State_Turn;
|
||||
} else {
|
||||
state = State_Destroy;
|
||||
_canDestroy = true;
|
||||
}
|
||||
}
|
||||
|
||||
// Removing the pointer ketchup-effect that's built into some devices
|
||||
if (wasFirstMovement) {
|
||||
dx = dy = 0;
|
||||
}
|
||||
|
||||
cxO = cx;
|
||||
cyO = cy;
|
||||
//LOGI("move delta: %f (%f, %f), %d\n", moveDelta, dx, dy, state);
|
||||
}
|
||||
} else {
|
||||
// Wasn't active, and isn't active!
|
||||
state = State_None;
|
||||
}
|
||||
|
||||
updateFeedbackProgressAlpha(now);
|
||||
|
||||
wasActive = isActive;
|
||||
return TurnDelta(dx, -dy);
|
||||
}
|
||||
|
||||
void updateFeedbackProgressAlpha(float now) {
|
||||
const float MinAlphaValue = -0.05f;
|
||||
if (_canDestroy) {
|
||||
// Hack to test out fading in feedback circle
|
||||
const float since = now - _startTurnTime;
|
||||
if (state == State_Deciding) {
|
||||
const float wantedAlpha = since / (0.001f*RemovalMilliseconds);
|
||||
_holder->alpha = wantedAlpha * wantedAlpha;
|
||||
} else {
|
||||
if (state == State_Destroy) {
|
||||
_holder->alpha = calcNewAlpha(_holder->alpha, 1);
|
||||
} else if (state == State_Turn || state == State_None) {
|
||||
_holder->alpha = calcNewAlpha(_holder->alpha, 0);
|
||||
}
|
||||
|
||||
}
|
||||
} else {
|
||||
_holder->alpha = MinAlphaValue;
|
||||
}
|
||||
//LOGI("state: %d, canDestroy: %d %d\n", state, _canDestroy, _forceCanUse);
|
||||
//LOGI("alpha: %f\n", _holder->alpha);
|
||||
}
|
||||
|
||||
bool isInsideArea(float x, float y) {
|
||||
return _area.isInside(x, y);
|
||||
}
|
||||
|
||||
int mode;
|
||||
|
||||
static float getSpeedSquared(Entity* m) {
|
||||
const float xd = m->x - m->xo;
|
||||
const float yd = m->y - m->yo;
|
||||
const float zd = m->z - m->zo;
|
||||
const float speedSquared = xd*xd + yd*yd + zd*zd;
|
||||
return speedSquared;
|
||||
}
|
||||
|
||||
void render(float alpha) {
|
||||
if (_options->getBooleanValue(OPTIONS_IS_JOY_TOUCH_AREA)) {
|
||||
fill( (int) (Gui::InvGuiScale * joyTouchArea._x0),
|
||||
(int) (Gui::InvGuiScale * joyTouchArea._y0),
|
||||
(int) (Gui::InvGuiScale * joyTouchArea._x1),
|
||||
(int) (Gui::InvGuiScale * joyTouchArea._y1), 0x40000000);//0x20ffffff);
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// Implementation for the IBuildInput part
|
||||
//
|
||||
virtual bool tickBuild(Player* player, BuildActionIntention* bai) {
|
||||
_lastPlayer = player;
|
||||
|
||||
if (state == State_Destroy) {
|
||||
if (!_sentFirstRemove) {
|
||||
*bai = BuildActionIntention((_forceCanUse?0:BuildActionIntention::BAI_FIRSTREMOVE) | BuildActionIntention::BAI_INTERACT);
|
||||
_sentFirstRemove = true;
|
||||
} else {
|
||||
*bai = BuildActionIntention((_forceCanUse?0:BuildActionIntention::BAI_REMOVE) | BuildActionIntention::BAI_INTERACT);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
// Rewind the queue, in case someone has used it up before
|
||||
Multitouch::rewind();
|
||||
const float now = getTimeS();
|
||||
allowPicking = false;
|
||||
bool handled = false;
|
||||
|
||||
while (Multitouch::next()) {
|
||||
MouseAction& m = Multitouch::getEvent();
|
||||
if (m.action == MouseAction::ACTION_MOVE) continue;
|
||||
|
||||
int areaId = _model.getPointerId(m.x, m.y, m.pointerId);
|
||||
if (areaId != AREA_TURN) continue;
|
||||
|
||||
allowPicking = true;
|
||||
//LOGI("down? %d, up? %d (%d, %d)\n", z && (m.data == MouseAction::DATA_DOWN), z && (m.data == MouseAction::DATA_UP), m.x, m.y);
|
||||
|
||||
if (_totalMoveDelta <= MaxBuildMovement && (m.data == MouseAction::DATA_UP && !handled)) {
|
||||
const float since = now - _lastBuildDownTime;
|
||||
//LOGI("move: (%d) %.2f - %f\n", state, _totalMoveDelta, since);
|
||||
if (state <= State_Deciding) {
|
||||
if (since >= 0.0f && since < 0.25f) {
|
||||
// We've pressed and released in haste; Let's build!
|
||||
*bai = BuildActionIntention(BuildActionIntention::BAI_BUILD | BuildActionIntention::BAI_ATTACK);
|
||||
handled = true;
|
||||
}
|
||||
}
|
||||
state = State_None;
|
||||
} else if (m.data == MouseAction::DATA_DOWN) {
|
||||
_lastBuildDownTime = now;
|
||||
_buildMovement = 0;
|
||||
state = State_Deciding;
|
||||
}
|
||||
}
|
||||
return handled;
|
||||
}
|
||||
|
||||
bool allowPicking;
|
||||
float alpha;
|
||||
SmoothFloat smoothAlpha;
|
||||
|
||||
RectangleArea screenArea;
|
||||
RectangleArea moveArea;
|
||||
RectangleArea joyTouchArea;
|
||||
RectangleArea inventoryArea;
|
||||
RectangleArea pauseArea;
|
||||
|
||||
private:
|
||||
IInputHolder* _holder;
|
||||
|
||||
// Turn
|
||||
int cid;
|
||||
float cxO, cyO;
|
||||
bool wasActive;
|
||||
|
||||
TouchAreaModel _model;
|
||||
IncludeExcludeArea _area;
|
||||
|
||||
bool _decidedTurnMode;
|
||||
|
||||
float _startTurnTime;
|
||||
float _totalMoveDelta;
|
||||
float _maxMovement;
|
||||
float _sensitivity;
|
||||
|
||||
Player* _lastPlayer;
|
||||
|
||||
// Build
|
||||
float _lastBuildDownTime;
|
||||
float _buildMovement;
|
||||
bool _sentFirstRemove;
|
||||
bool _canDestroy;
|
||||
bool _forceCanUse;
|
||||
|
||||
int state;
|
||||
static const int State_None = 0;
|
||||
static const int State_Deciding = 1;
|
||||
static const int State_Turn = 2;
|
||||
static const int State_Destroy = 3;
|
||||
static const int State_Build = 4; // Will never happen
|
||||
|
||||
static const int MaxBuildMovement = 20;
|
||||
static const int RemovalMilliseconds = 400;
|
||||
|
||||
static const int AREA_TURN = 100;
|
||||
Options* _options;
|
||||
};
|
||||
|
||||
class Minecraft;
|
||||
|
||||
#if defined(_MSC_VER)
|
||||
#pragma warning( disable : 4355 ) // 'this' pointer in initialization list which is perfectly legal
|
||||
#endif
|
||||
|
||||
class TouchInputHolder: public IInputHolder
|
||||
{
|
||||
public:
|
||||
TouchInputHolder(Minecraft* mc, Options* options)
|
||||
: _mc(mc),
|
||||
_move(mc, options),
|
||||
_turnBuild(UnifiedTurnBuild::MODE_DELTA, mc->width, mc->height, (float)MovementLimit, 1, this, mc)
|
||||
{
|
||||
onConfigChanged(createConfig(mc));
|
||||
}
|
||||
~TouchInputHolder() {
|
||||
}
|
||||
|
||||
virtual void onConfigChanged(const Config& c) {
|
||||
_move.onConfigChanged(c);
|
||||
_turnBuild.moveArea = _move.getRectangleArea();
|
||||
_turnBuild.pauseArea = _move.getPauseRectangleArea();
|
||||
_turnBuild.inventoryArea = _mc->gui.getRectangleArea( _mc->options.getBooleanValue(OPTIONS_IS_LEFT_HANDED)? 1 : -1 );
|
||||
_turnBuild.setSensitivity(c.options->getBooleanValue(OPTIONS_IS_JOY_TOUCH_AREA)? 1.8f : 1.0f);
|
||||
((ITurnInput*)&_turnBuild)->onConfigChanged(c);
|
||||
}
|
||||
|
||||
virtual bool allowPicking() {
|
||||
const int* pointerIds;
|
||||
int pointerCount = Multitouch::getActivePointerIds(&pointerIds);
|
||||
for (int i = 0; i < pointerCount; ++i) {
|
||||
int p = pointerIds[i];
|
||||
const float x = Multitouch::getX(p);
|
||||
const float y = Multitouch::getY(p);
|
||||
|
||||
if (_turnBuild.isInsideArea(x, y)) {
|
||||
mousex = x;
|
||||
mousey = y;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
// return _turnBuild.allowPicking;
|
||||
}
|
||||
|
||||
virtual void render(float alpha) {
|
||||
_turnBuild.render(alpha);
|
||||
}
|
||||
|
||||
virtual IMoveInput* getMoveInput() { return &_move; }
|
||||
virtual ITurnInput* getTurnInput() { return &_turnBuild; }
|
||||
virtual IBuildInput* getBuildInput() { return &_turnBuild; }
|
||||
|
||||
private:
|
||||
TouchscreenInput_TestFps _move;
|
||||
UnifiedTurnBuild _turnBuild;
|
||||
|
||||
Minecraft* _mc;
|
||||
|
||||
static const int MovementLimit = 200; // per update
|
||||
};
|
||||
|
||||
|
||||
@@ -1,88 +1,86 @@
|
||||
#ifndef NET_MINECRAFT_CLIENT_PLAYER_INPUT_TOUCHSCREEN_TouchTurnInput_H__
|
||||
#define NET_MINECRAFT_CLIENT_PLAYER_INPUT_TOUCHSCREEN_TouchTurnInput_H__
|
||||
|
||||
#include "../ITurnInput.h"
|
||||
#include "TouchAreaModel.h"
|
||||
#include "../../../../platform/input/Multitouch.h"
|
||||
|
||||
class TouchTurnInput: public ITurnInput
|
||||
{
|
||||
public:
|
||||
static const int MODE_OFFSET = 1;
|
||||
static const int MODE_DELTA = 2;
|
||||
|
||||
TouchTurnInput(int mode_)
|
||||
: mode(mode_),
|
||||
cxO(0), cyO(0),
|
||||
wasActive(false)
|
||||
{
|
||||
}
|
||||
|
||||
TurnDelta getTurnDelta() {
|
||||
float dx = 0, dy = 0;
|
||||
|
||||
float cx = 0;
|
||||
float cy = 0;
|
||||
bool isActive = false;
|
||||
|
||||
const int* pointerIds;
|
||||
int pointerCount = Multitouch::getActivePointerIds(&pointerIds);
|
||||
for (int i = 0; i < pointerCount; ++i) {
|
||||
int p = pointerIds[i];
|
||||
int x = Multitouch::getX(p);
|
||||
int y = Multitouch::getY(p);
|
||||
int areaId = _model.getPointerId(x, y, p);
|
||||
|
||||
if (areaId == AREA_TURN) {
|
||||
isActive = true;
|
||||
cx = (float)x * 0.5f;
|
||||
cy = (float)y * -0.5f;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (MODE_OFFSET == mode) {
|
||||
//float dt = getDeltaTime();
|
||||
//const float MaxTurnX = 250.0f;
|
||||
//const float MaxTurnY = 200.0f;
|
||||
//float cx = isActive? Controller::getX(cid) : cxO * 0.7f;
|
||||
//float cy = isActive? Controller::getY(cid) : cyO * 0.7f;
|
||||
//dx = linearTransform( cx, 0.1f, MaxTurnX ) * dt;
|
||||
//dy = linearTransform( cy, 0.1f, MaxTurnY ) * dt;
|
||||
//cxO = cx;
|
||||
//cyO = cy;
|
||||
} else
|
||||
if (MODE_DELTA == mode && (wasActive || isActive)) {
|
||||
// const float dt = getDeltaTime();
|
||||
// const float MaxTurnX = 100.0f;
|
||||
// const float MaxTurnY = 100.0f;
|
||||
const float DeadZone = 0;//0.25f * dt;//0.02f;
|
||||
|
||||
if (!wasActive) {
|
||||
cxO = cx;
|
||||
cyO = cy;
|
||||
}
|
||||
if (isActive) {
|
||||
dx = linearTransform(cx - cxO, DeadZone);// * MaxTurnX;
|
||||
dy = linearTransform(cy - cyO, DeadZone);// * MaxTurnY;
|
||||
cxO = cx;
|
||||
cyO = cy;
|
||||
}
|
||||
}
|
||||
|
||||
wasActive = isActive;
|
||||
return TurnDelta(dx, -dy);
|
||||
}
|
||||
|
||||
int mode;
|
||||
private:
|
||||
int cid;
|
||||
float cxO, cyO;
|
||||
bool wasActive;
|
||||
|
||||
TouchAreaModel _model;
|
||||
|
||||
static const int AREA_TURN = 100;
|
||||
};
|
||||
|
||||
#endif /*NET_MINECRAFT_CLIENT_PLAYER_INPUT_TOUCHSCREEN_TouchTurnInput_H__*/
|
||||
#pragma once
|
||||
|
||||
#include "../ITurnInput.h"
|
||||
#include "TouchAreaModel.h"
|
||||
#include "../../../../platform/input/Multitouch.h"
|
||||
|
||||
class TouchTurnInput: public ITurnInput
|
||||
{
|
||||
public:
|
||||
static const int MODE_OFFSET = 1;
|
||||
static const int MODE_DELTA = 2;
|
||||
|
||||
TouchTurnInput(int mode_)
|
||||
: mode(mode_),
|
||||
cxO(0), cyO(0),
|
||||
wasActive(false)
|
||||
{
|
||||
}
|
||||
|
||||
TurnDelta getTurnDelta() {
|
||||
float dx = 0, dy = 0;
|
||||
|
||||
float cx = 0;
|
||||
float cy = 0;
|
||||
bool isActive = false;
|
||||
|
||||
const int* pointerIds;
|
||||
int pointerCount = Multitouch::getActivePointerIds(&pointerIds);
|
||||
for (int i = 0; i < pointerCount; ++i) {
|
||||
int p = pointerIds[i];
|
||||
int x = Multitouch::getX(p);
|
||||
int y = Multitouch::getY(p);
|
||||
int areaId = _model.getPointerId(x, y, p);
|
||||
|
||||
if (areaId == AREA_TURN) {
|
||||
isActive = true;
|
||||
cx = (float)x * 0.5f;
|
||||
cy = (float)y * -0.5f;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (MODE_OFFSET == mode) {
|
||||
//float dt = getDeltaTime();
|
||||
//const float MaxTurnX = 250.0f;
|
||||
//const float MaxTurnY = 200.0f;
|
||||
//float cx = isActive? Controller::getX(cid) : cxO * 0.7f;
|
||||
//float cy = isActive? Controller::getY(cid) : cyO * 0.7f;
|
||||
//dx = linearTransform( cx, 0.1f, MaxTurnX ) * dt;
|
||||
//dy = linearTransform( cy, 0.1f, MaxTurnY ) * dt;
|
||||
//cxO = cx;
|
||||
//cyO = cy;
|
||||
} else
|
||||
if (MODE_DELTA == mode && (wasActive || isActive)) {
|
||||
// const float dt = getDeltaTime();
|
||||
// const float MaxTurnX = 100.0f;
|
||||
// const float MaxTurnY = 100.0f;
|
||||
const float DeadZone = 0;//0.25f * dt;//0.02f;
|
||||
|
||||
if (!wasActive) {
|
||||
cxO = cx;
|
||||
cyO = cy;
|
||||
}
|
||||
if (isActive) {
|
||||
dx = linearTransform(cx - cxO, DeadZone);// * MaxTurnX;
|
||||
dy = linearTransform(cy - cyO, DeadZone);// * MaxTurnY;
|
||||
cxO = cx;
|
||||
cyO = cy;
|
||||
}
|
||||
}
|
||||
|
||||
wasActive = isActive;
|
||||
return TurnDelta(dx, -dy);
|
||||
}
|
||||
|
||||
int mode;
|
||||
private:
|
||||
int cid;
|
||||
float cxO, cyO;
|
||||
bool wasActive;
|
||||
|
||||
TouchAreaModel _model;
|
||||
|
||||
static const int AREA_TURN = 100;
|
||||
};
|
||||
|
||||
|
||||
@@ -1,80 +1,78 @@
|
||||
#ifndef NET_MINECRAFT_CLIENT_PLAYER_INPUT_TOUCHSCREEN_TouchscreenInput_H__
|
||||
#define NET_MINECRAFT_CLIENT_PLAYER_INPUT_TOUCHSCREEN_TouchscreenInput_H__
|
||||
|
||||
//package net.minecraft.client.player;
|
||||
|
||||
#include "../IMoveInput.h"
|
||||
#include "../../../gui/GuiComponent.h"
|
||||
#include "TouchAreaModel.h"
|
||||
#include "../../../renderer/RenderChunk.h"
|
||||
|
||||
class Options;
|
||||
class Player;
|
||||
class Minecraft;
|
||||
class PolygonArea;
|
||||
|
||||
// @todo: extract a separate MoveInput (-> merge XperiaPlayInput)
|
||||
class TouchscreenInput_TestFps: public IMoveInput,
|
||||
public GuiComponent
|
||||
{
|
||||
public:
|
||||
static const int KEY_UP = 0;
|
||||
static const int KEY_DOWN = 1;
|
||||
static const int KEY_LEFT = 2;
|
||||
static const int KEY_RIGHT = 3;
|
||||
static const int KEY_JUMP = 4;
|
||||
static const int KEY_SNEAK = 5;
|
||||
static const int KEY_CRAFT = 6;
|
||||
static const int NumKeys = 7;
|
||||
|
||||
TouchscreenInput_TestFps(Minecraft* mc, Options* options);
|
||||
~TouchscreenInput_TestFps();
|
||||
|
||||
void onConfigChanged(const Config& c);
|
||||
|
||||
void tick(Player* player);
|
||||
void render(float a);
|
||||
|
||||
void setKey(int key, bool state);
|
||||
void releaseAllKeys();
|
||||
|
||||
const RectangleArea& getRectangleArea();
|
||||
const RectangleArea& getPauseRectangleArea();
|
||||
|
||||
private:
|
||||
void clear();
|
||||
|
||||
RectangleArea _boundingRectangle;
|
||||
|
||||
bool _keys[NumKeys];
|
||||
Options* _options;
|
||||
|
||||
bool _pressedJump;
|
||||
bool _forward;
|
||||
bool _northJump;
|
||||
bool _renderFlightImage;
|
||||
TouchAreaModel _model;
|
||||
Minecraft* _minecraft;
|
||||
|
||||
RectangleArea* aLeft;
|
||||
RectangleArea* aRight;
|
||||
RectangleArea* aUp;
|
||||
RectangleArea* aDown;
|
||||
RectangleArea* aPause;
|
||||
RectangleArea* aChat;
|
||||
//RectangleArea* aUpJump;
|
||||
RectangleArea* aJump;
|
||||
RectangleArea* aUpLeft;
|
||||
RectangleArea* aUpRight;
|
||||
bool _pauseIsDown;
|
||||
|
||||
RenderChunk _render;
|
||||
bool _allowHeightChange;
|
||||
float _sneakTapTime;
|
||||
|
||||
bool _buttons[8];
|
||||
bool isButtonDown(int areaId);
|
||||
void rebuild();
|
||||
};
|
||||
|
||||
#endif /*NET_MINECRAFT_CLIENT_PLAYER_INPUT_TOUCHSCREEN_TouchscreenInput_H__*/
|
||||
#pragma once
|
||||
|
||||
//package net.minecraft.client.player;
|
||||
|
||||
#include "../IMoveInput.h"
|
||||
#include "../../../gui/GuiComponent.h"
|
||||
#include "TouchAreaModel.h"
|
||||
#include "../../../renderer/RenderChunk.h"
|
||||
|
||||
class Options;
|
||||
class Player;
|
||||
class Minecraft;
|
||||
class PolygonArea;
|
||||
|
||||
// @todo: extract a separate MoveInput (-> merge XperiaPlayInput)
|
||||
class TouchscreenInput_TestFps: public IMoveInput,
|
||||
public GuiComponent
|
||||
{
|
||||
public:
|
||||
static const int KEY_UP = 0;
|
||||
static const int KEY_DOWN = 1;
|
||||
static const int KEY_LEFT = 2;
|
||||
static const int KEY_RIGHT = 3;
|
||||
static const int KEY_JUMP = 4;
|
||||
static const int KEY_SNEAK = 5;
|
||||
static const int KEY_CRAFT = 6;
|
||||
static const int NumKeys = 7;
|
||||
|
||||
TouchscreenInput_TestFps(Minecraft* mc, Options* options);
|
||||
~TouchscreenInput_TestFps();
|
||||
|
||||
void onConfigChanged(const Config& c);
|
||||
|
||||
void tick(Player* player);
|
||||
void render(float a);
|
||||
|
||||
void setKey(int key, bool state);
|
||||
void releaseAllKeys();
|
||||
|
||||
const RectangleArea& getRectangleArea();
|
||||
const RectangleArea& getPauseRectangleArea();
|
||||
|
||||
private:
|
||||
void clear();
|
||||
|
||||
RectangleArea _boundingRectangle;
|
||||
|
||||
bool _keys[NumKeys];
|
||||
Options* _options;
|
||||
|
||||
bool _pressedJump;
|
||||
bool _forward;
|
||||
bool _northJump;
|
||||
bool _renderFlightImage;
|
||||
TouchAreaModel _model;
|
||||
Minecraft* _minecraft;
|
||||
|
||||
RectangleArea* aLeft;
|
||||
RectangleArea* aRight;
|
||||
RectangleArea* aUp;
|
||||
RectangleArea* aDown;
|
||||
RectangleArea* aPause;
|
||||
RectangleArea* aChat;
|
||||
//RectangleArea* aUpJump;
|
||||
RectangleArea* aJump;
|
||||
RectangleArea* aUpLeft;
|
||||
RectangleArea* aUpRight;
|
||||
bool _pauseIsDown;
|
||||
|
||||
RenderChunk _render;
|
||||
bool _allowHeightChange;
|
||||
float _sneakTapTime;
|
||||
|
||||
bool _buttons[8];
|
||||
bool isButtonDown(int areaId);
|
||||
void rebuild();
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user