Skip to content

Commit

Permalink
Merge pull request #140 from TurningWheel/develop
Browse files Browse the repository at this point in the history
test
  • Loading branch information
WALLOFJUSTICE authored Mar 5, 2022
2 parents 03f2a04 + f4590b6 commit 016ab51
Show file tree
Hide file tree
Showing 10 changed files with 367 additions and 186 deletions.
8 changes: 4 additions & 4 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -159,11 +159,11 @@ if( NOT WIN32 )
set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} ${OPTIMIZATION_LEVEL} -ffast-math -funroll-loops -fstrict-aliasing -mcpu=cortex-a8 -mfpu=neon -mfloat-abi=softfp -g -fuse-ld=gold -fuse-linker-plugin -fsingle-precision-constant")
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} ${OPTIMIZATION_LEVEL} -ffast-math -funroll-loops -fstrict-aliasing -mcpu=cortex-a8 -mfpu=neon -mfloat-abi=softfp -g -fuse-ld=gold -fuse-linker-plugin -fsingle-precision-constant")
else()
set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -pedantic -Wno-multichar -pg -ffast-math -funroll-loops -fstrict-aliasing")
set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -Wpedantic -Wno-multichar -pg -ffast-math -funroll-loops -fstrict-aliasing")
#set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -pg -fsanitize=address -fno-omit-frame-pointer -fsanitize=undefined -fno-sanitize-recover -Wreturn-type -Werror=return-type")
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -pedantic -Wno-multichar -pg")
set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} -pedantic -Wno-multichar ${OPTIMIZATION_LEVEL} -ffast-math -funroll-loops -fstrict-aliasing")
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -pedantic -Wno-multichar ${OPTIMIZATION_LEVEL}")
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -Wpedantic -Wno-multichar -pg")
set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} -Wpedantic -Wno-multichar ${OPTIMIZATION_LEVEL} -ffast-math -funroll-loops -fstrict-aliasing")
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -Wpedantic -Wno-multichar ${OPTIMIZATION_LEVEL}")
endif()
if (APPLE)
set (Apple 1)
Expand Down
26 changes: 0 additions & 26 deletions src/game.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -836,32 +836,6 @@ void gameLogic(void)
{
fadefinished = true;
}
if ( multiplayer == SERVER && introstage == 3 )
{
// machinegun this message to clients to make sure they get it!
for ( c = 1; c < MAXPLAYERS; c++ )
{
if ( client_disconnected[c] || players[c]->isLocalPlayer() )
{
continue;
}
strcpy((char*)net_packet->data, "STRT");
SDLNet_Write32(svFlags, &net_packet->data[4]);
SDLNet_Write32(uniqueGameKey, &net_packet->data[8]);
if ( loadingsavegame == 0 )
{
net_packet->data[12] = 0;
}
else
{
net_packet->data[12] = 1;
}
net_packet->address.host = net_clients[c - 1].host;
net_packet->address.port = net_clients[c - 1].port;
net_packet->len = 13;
sendPacket(net_sock, -1, net_packet, c - 1);
}
}
}
else
{
Expand Down
2 changes: 1 addition & 1 deletion src/menu.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -317,4 +317,4 @@ enum CharacterDLCValidation : int
INVALID_REQUIREDLC1,
INVALID_REQUIREDLC2,
INVALID_REQUIRE_ACHIEVEMENT
};
};
42 changes: 15 additions & 27 deletions src/net.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
#include "colors.hpp"
#include "mod_tools.hpp"
#include "lobbies.hpp"
#include "ui/MainMenu.hpp"

NetHandler* net_handler = nullptr;

Expand Down Expand Up @@ -2449,18 +2450,16 @@ void clientHandlePacket()
// server or player shut down
else if (packetId == 'DISC')
{
client_disconnected[net_packet->data[4]] = true;
if (net_packet->data[4] == 0)
{
// server shutdown
if (!victory)
{
printlog("The remote server has shut down.\n");
pauseGame(2, 0);
// TODO display disconnect window
// &buttonCloseAndEndGameConfirm on okay
MainMenu::disconnectedFromServer();
}
}
client_disconnected[net_packet->data[4]] = true;
return;
}

Expand Down Expand Up @@ -4345,32 +4344,14 @@ void clientHandlePacket()
}

// game restart
if (packetId == 'STRT')
if (packetId == 'RSTR')
{
if ( !intro )
{
// intro is true if starting from main menu, otherwise we're restarting the game.
// set the main menu camera to the player camera coordinates if restarting midgame.
menucam.x = cameras[clientnum].x;
menucam.y = cameras[clientnum].y;
menucam.z = cameras[clientnum].z;
menucam.ang = cameras[clientnum].ang;
menucam.vang = cameras[clientnum].vang;
}
intro = true;
client_disconnected[0] = true;
svFlags = SDLNet_Read32(&net_packet->data[4]);
uniqueGameKey = SDLNet_Read32(&net_packet->data[8]);
//TODO anything we gotta do for the new UI?
//probably not buttonCloseSubwindow().
//buttonCloseSubwindow(NULL);
numplayers = 0;
introstage = 3;
if ( net_packet->data[12] == 0 )
{
loadingsavegame = 0; // the server said we're not loading a saved game.
}
fadeout = true;
if (net_packet->data[12] == 0) {
loadingsavegame = 0;
}
MainMenu::beginFade(MainMenu::FadeDestination::GameStart);
return;
}

Expand Down Expand Up @@ -4540,6 +4521,13 @@ void serverHandlePacket()
return;
}

// network scan
else if (packetId == 'SCAN')
{
MainMenu::handleScanPacket();
return;
}

// pause game
else if (packetId == 'PAUS')
{
Expand Down
13 changes: 13 additions & 0 deletions src/opengl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -522,6 +522,19 @@ void glDrawVoxel(view_t* camera, Entity* entity, int mode)
glRotatef(rotz, 0, 0, 1); // rotate pitch
glRotatef(rotx, 1, 0, 0); // rotate roll
glTranslatef(entity->focalx * 2, -entity->focalz * 2, entity->focaly * 2);
#ifndef EDITOR
static ConsoleVariable<bool> reverseWhip("/reversewhip", false);
if (*reverseWhip) {
int chop = entity->skill[0];
if (entity->behavior == &actHudWeapon && entity->sprite == 868 &&
(chop == 1 || chop == 2 || chop == 4 || chop == 5)) {
// whips get turned around when attacking
// gross hack, but it works, and we don't have quaternions. so this is way easier
glRotatef(180, 0, 1, 0);
glRotatef(60, 0, 0, 1);
}
}
#endif
glScalef(entity->scalex, entity->scalez, entity->scaley);
if ( mode == REALCOLORS )
{
Expand Down
89 changes: 64 additions & 25 deletions src/ui/Frame.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -390,28 +390,31 @@ void Frame::draw(SDL_Rect _size, SDL_Rect _actualSize, const std::vector<const W
for (int i = listStart; i < list.size(); ++i) {
entry_t& entry = *list[i];

// draw selection background
if (selection == i && selectedEntryColor) {
// draw highlighted background
#ifndef EDITOR
if (activated || !inputs.hasController(owner)) {
if (activated || !inputs.hasController(owner)) {
#else
{
{
#endif
SDL_Rect pos;
pos.x = _size.x + border + listOffset.x - scroll.x;
pos.y = _size.y + border + listOffset.y + i * entrySize - scroll.y;
pos.w = _size.w;
pos.h = entrySize;

SDL_Rect dest;
dest.x = std::max(_size.x, pos.x);
dest.y = std::max(_size.y, pos.y);
dest.w = pos.w - (dest.x - pos.x) - std::max(0, (pos.x + pos.w) - (_size.x + _size.w));
dest.h = pos.h - (dest.y - pos.y) - std::max(0, (pos.y + pos.h) - (_size.y + _size.h));

SDL_Rect pos;
pos.x = _size.x + border + listOffset.x - scroll.x;
pos.y = _size.y + border + listOffset.y + i * entrySize - scroll.y;
pos.w = _size.w;
pos.h = entrySize;

SDL_Rect dest;
dest.x = std::max(_size.x, pos.x);
dest.y = std::max(_size.y, pos.y);
dest.w = pos.w - (dest.x - pos.x) - std::max(0, (pos.x + pos.w) - (_size.x + _size.w));
dest.h = pos.h - (dest.y - pos.y) - std::max(0, (pos.y + pos.h) - (_size.y + _size.h));

if (activation == &entry && activatedEntryColor) {
white->drawColor(nullptr, dest, viewport, activatedEntryColor);
}
else if (selection == i && selectedEntryColor) {
white->drawColor(nullptr, dest, viewport, selectedEntryColor);
}
}
}

// draw an image if applicable
if (entry.text.empty()) {
Expand Down Expand Up @@ -802,10 +805,12 @@ Frame::result_t Frame::process(SDL_Rect _size, SDL_Rect _actualSize, const std::
if (input.binary("MenuScrollRight")) {
this->actualSize.x += std::min(this->actualSize.x + 5, this->actualSize.w - _size.w);
usable = result.usable = false;
syncScroll();
}
else if (input.binary("MenuScrollLeft")) {
this->actualSize.x -= std::max(this->actualSize.x - 5, 0);
usable = result.usable = false;
syncScroll();
}
}

Expand All @@ -814,10 +819,12 @@ Frame::result_t Frame::process(SDL_Rect _size, SDL_Rect _actualSize, const std::
if (input.binary("MenuScrollDown")) {
this->actualSize.y = std::min(this->actualSize.y + 5, this->actualSize.h - _size.h);
usable = result.usable = false;
syncScroll();
}
else if (input.binary("MenuScrollUp")) {
this->actualSize.y = std::max(this->actualSize.y - 5, 0);
usable = result.usable = false;
syncScroll();
}
}
}
Expand All @@ -832,12 +839,12 @@ Frame::result_t Frame::process(SDL_Rect _size, SDL_Rect _actualSize, const std::
if (parent != nullptr && !hollow && rectContainsPoint(fullSize, omousex, omousey) && usable) {
bool mwheeldown = false;
bool mwheelup = false;
if (input.consumeBinaryToggle("MenuMouseWheelDown")) {
mwheeldown = true;
}
if (input.consumeBinaryToggle("MenuMouseWheelUp")) {
mwheelup = true;
}
if (input.consumeBinaryToggle("MenuMouseWheelDown")) {
mwheeldown = true;
}
if (input.consumeBinaryToggle("MenuMouseWheelUp")) {
mwheelup = true;
}
if (allowScrolling && allowScrollBinds) {
if (mwheeldown || mwheelup) {
usable = result.usable = false;
Expand Down Expand Up @@ -867,8 +874,18 @@ Frame::result_t Frame::process(SDL_Rect _size, SDL_Rect _actualSize, const std::
}
}

this->actualSize.x += scrollInertiaX * entrySize * 2;
this->actualSize.y += scrollInertiaY * entrySize * 2;
if (scrollInertiaX) {
this->actualSize.x += scrollInertiaX * entrySize * 2;
this->actualSize.x = std::min(std::max(0, this->actualSize.x),
std::max(0, this->actualSize.w - size.w));
syncScroll();
}
if (scrollInertiaY) {
this->actualSize.y += scrollInertiaY * entrySize * 2;
this->actualSize.y = std::min(std::max(0, this->actualSize.y),
std::max(0, this->actualSize.h - size.h));
syncScroll();
}

if (fabs(scrollInertiaX) > 0.0) {
scrollInertiaX *= .9;
Expand Down Expand Up @@ -930,6 +947,7 @@ Frame::result_t Frame::process(SDL_Rect _size, SDL_Rect _actualSize, const std::
float winFactor = ((float)_size.w / (float)this->actualSize.w);
this->actualSize.x = (mousex - omousex) / winFactor + oldSliderX;
this->actualSize.x = std::min(std::max(0, this->actualSize.x), std::max(0, this->actualSize.w - size.w));
syncScroll();
}
usable = result.usable = false;
ticks = -1; // hack to fix sliders in drop downs
Expand All @@ -945,6 +963,7 @@ Frame::result_t Frame::process(SDL_Rect _size, SDL_Rect _actualSize, const std::
if (mousestatus[SDL_BUTTON_LEFT]) {
this->actualSize.x += omousex < handleRect.x ? -std::min(entrySize, size.w) : std::min(entrySize, size.w);
this->actualSize.x = std::min(std::max(0, this->actualSize.x), std::max(0, this->actualSize.w - size.w));
syncScroll();
mousestatus[SDL_BUTTON_LEFT] = 0;
}
usable = result.usable = false;
Expand Down Expand Up @@ -980,6 +999,7 @@ Frame::result_t Frame::process(SDL_Rect _size, SDL_Rect _actualSize, const std::
float winFactor = ((float)_size.h / (float)this->actualSize.h);
this->actualSize.y = (mousey - omousey) / winFactor + oldSliderY;
this->actualSize.y = std::min(std::max(0, this->actualSize.y), std::max(0, this->actualSize.h - size.h));
syncScroll();
}
usable = result.usable = false;
ticks = -1; // hack to fix sliders in drop downs
Expand All @@ -995,6 +1015,7 @@ Frame::result_t Frame::process(SDL_Rect _size, SDL_Rect _actualSize, const std::
if (mousestatus[SDL_BUTTON_LEFT]) {
this->actualSize.y += omousey < handleRect.y ? -std::min(entrySize, size.h) : std::min(entrySize, size.h);
this->actualSize.y = std::min(std::max(0, this->actualSize.y), std::max(0, this->actualSize.h - size.h));
syncScroll();
mousestatus[SDL_BUTTON_LEFT] = 0;
}
usable = result.usable = false;
Expand Down Expand Up @@ -1723,6 +1744,7 @@ void Frame::scrollToSelection(bool scroll_to_top) {
}

void Frame::activateEntry(entry_t& entry) {
activation = &entry;
if (keystatus[SDL_SCANCODE_LCTRL] || keystatus[SDL_SCANCODE_RCTRL]) {
if (entry.ctrlClick) {
(*entry.ctrlClick)(entry);
Expand Down Expand Up @@ -2178,3 +2200,20 @@ void Frame::drawImage(const image_t* image, const SDL_Rect& _size, const SDL_Rec
}
}
}

void Frame::addSyncScrollTarget(const char* name) {
syncScrollTargets.push_back(std::move(std::string(name)));
}

void Frame::syncScroll() {
assert(gui);
for (auto name : syncScrollTargets) {
auto frame = gui->findFrame(name.c_str());
if (frame) {
auto _size = frame->getActualSize();
_size.x = actualSize.x;
_size.y = actualSize.y;
frame->setActualSize(_size);
}
}
}
13 changes: 13 additions & 0 deletions src/ui/Frame.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,13 @@ class Frame : public Widget {
//! @param scroll_to_top if true, scroll the selection to the very top of the frame
void scrollToSelection(bool scroll_to_top = false);

//! adds a frame to an internal list which will match our scroll values at all times.
//! @param name the name of the frame to sync with
void addSyncScrollTarget(const char* name);

//! synchronizes scrolling with sync scroll targets
void syncScroll();

virtual type_t getType() const override { return WIDGET_FRAME; }
const char* getFont() const { return font.c_str(); }
const int getBorder() const { return border; }
Expand Down Expand Up @@ -319,6 +326,7 @@ class Frame : public Widget {
void setHigh(bool b) { borderStyle = b ? BORDER_BEVEL_HIGH : BORDER_BEVEL_LOW; }
void setColor(const Uint32& _color) { color = _color; }
void setSelectedEntryColor(const Uint32& _color) { selectedEntryColor = _color; }
void setActivatedEntryColor(const Uint32& _color) { activatedEntryColor = _color; }
void setBorderColor(const Uint32& _color) { borderColor = _color; }
void setDisabled(const bool _disabled) { disabled = _disabled; }
void setHollow(const bool _hollow) { hollow = _hollow; }
Expand All @@ -332,6 +340,7 @@ class Frame : public Widget {
void setClickable(const bool _clickable) { clickable = _clickable; }
void setDontTickChildren(const bool b) { dontTickChildren = b; }
void setEntrySize(int _size) { entrySize = _size; }
void setActivation(entry_t* entry) { activation = entry; }

private:
Uint32 ticks = 0; //!< number of engine ticks this frame has persisted
Expand All @@ -342,6 +351,7 @@ class Frame : public Widget {
border_style_t borderStyle = BORDER_BEVEL_HIGH; //!< border style
Uint32 color = 0; //!< the frame's color
Uint32 selectedEntryColor = 0; //!< selected entry color
Uint32 activatedEntryColor = 0; //!< activated entry color
Uint32 borderColor = 0; //!< the frame's border color (only used for flat border)
const char* tooltip = nullptr; //!< points to the tooltip that should be displayed by the (master) frame, or nullptr if none should be displayed
bool hollow = false; //!< if true, the frame doesn't have a solid background
Expand All @@ -352,6 +362,7 @@ class Frame : public Widget {
bool dropDown = false; //!< if true, the frame is destroyed when specific inputs register
Uint32 dropDownClicked = 0; //!< key states stored for removing drop downs
int selection = -1; //!< entry selection
entry_t* activation = nullptr; //!< activated entry
bool allowScrollBinds = true; //!< if true, scroll wheel + right stick can scroll frame
bool allowScrolling = false; //!< must be enabled for any kind of scrolling/actualSize to work
bool scrollbars = true; //!< must be true for sliders to be drawn/usable
Expand All @@ -373,6 +384,8 @@ class Frame : public Widget {
std::vector<Slider*> sliders;
std::vector<entry_t*> list;

std::vector<std::string> syncScrollTargets;

//! activate the given list entry
//! @param entry the entry to activate
void activateEntry(entry_t& entry);
Expand Down
2 changes: 1 addition & 1 deletion src/ui/GameUI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15559,7 +15559,7 @@ void doFrames() {
{
++gui_ticks;
}
(void)gui->process();
(void)gui->process();

gui->predraw();
gui->draw();
Expand Down
Loading

0 comments on commit 016ab51

Please sign in to comment.