Skip to content

Commit

Permalink
Framework Cleanup (no more client code in fw) (mehah#666)
Browse files Browse the repository at this point in the history
* Moved <client/...> includes from framework (we should never cross contaminate fw/client)

GraphicalApplication was the biggest offender, we need to ensure that this is a base graphical application class and not a client specific class.
Created UIQrCode widget
Minor additions and clean up

* Fix for latest version

* Finished, no more client code in the framework!

* Update README

* Revert

* fix cmake build

* Update review suggestions

Remove `image-source-base64` in favour of `image-source: base64:/path/image`

* Added CHANGELOG.md to help with noting breaking changes

* More framework improvements and some client improvements:

- Readd FRAMEWORK_GRAPHICS (so we can have no graphics support)
- Added creatureDiagonalWalkSpeed/playerDiagonalWalkSpeed upgrade_classification
- Added getCountOrSubType to Item lua binding
- Added startEvent to EventDispatcher (to start stored ScheduledEvent's)
- Removed g_drawPool from the application.cpp (we use dispatchPoll)
- Added startTime calculator when logging module starts
- Allow commenting out otml using #
- Added some math functions
- Added onAdopted/onAbandoned to UIWidget for when they are added to/from parent UIWidget's
- Added some more helper methods to UIWidget
- Added visibleOnly to UIWidget getChildBefore/getChildAfter methods
- Added onHovered for only hovered widget events
- Make getChildIndex take child as optional parameter, if not provided it returns this widgets child index
- Added sha1Encrpyt method
- General clean up

* Rename ApplicationDrawEvents#setLoadingAsyncTexture to onLoadingAsyncTextureChanged

* Update setup.otml

* Added a todo

* Clean up

* Revert old code (oops)

* Reverting onAdopted, etc

* Add improved version

* Improve getHoveredChild

* Recommended fixes/clean up

* Moved missed graphical sources to FRAMEWORK_GRAPHICS
  • Loading branch information
BenDol authored Dec 8, 2023
1 parent 72f7d3d commit c8ae6c1
Show file tree
Hide file tree
Showing 73 changed files with 1,093 additions and 250 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Changelog

## 05-12-2023
### Breaking API Changes
- `UIWidget` property `qr-code` & `qr-code-border` replaced with `UIQrCode` properties `code` & `code-border`
- `image-source-base64` replaced with `image-source: base64:/path/to/image`
- `#include "shadermanager.h"` moved to `#include <framework/graphics/shadermanager.h>`
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,9 @@
- Colored text [@conde2](https://github.com/conde2)
- widget:setColoredText("{Colored text, #ff00ff} normal text")
- QR Code support, with auto generate it from string [@conde2]
- qr-code-border: 2
- qr-code: Hail OTClient Redemption - Conde2 Dev
- UIQrCode:
- code-border: 2
- code: Hail OTClient Redemption - Conde2 Dev
- Smooth Walk Elevation Feature by [@SkullzOTS](https://github.com/SkullzOTS)
- View Feature: [Gyazo](https://i.gyazo.com/af0ed0f15a9e4d67bd4d0b2847bd6be7.gif)
- To enable just go to [modules/game_features/features.lua](https://github.com/mehah/otclient/blob/main/modules/game_features/features.lua#L5), and uncomment line 5 (g_game.enableFeature(GameSmoothWalkElevation)).
Expand Down
4 changes: 4 additions & 0 deletions data/setup.otml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ game
shield-blink-ticks: 500
volatile-square-duration: 1000
adjust-creature-information-based-crop-size: false
diagonal-walk-speed: 3

player
diagonal-walk-speed: 3

render
invisible-ticks-per-frame: 500
Expand Down
100 changes: 55 additions & 45 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ project(otclient)
# *****************************************************************************
# Options
# *****************************************************************************
option(TOGGLE_FRAMEWORK_GRAPHICS "Use Graphics " ON)
option(TOGGLE_FRAMEWORK_SOUND "Use SOUND " ON)
option(TOGGLE_FRAMEWORK_XML "Use XML " ON)
option(TOGGLE_FRAMEWORK_NET "Use NET " ON)
Expand Down Expand Up @@ -50,6 +51,9 @@ endif()

# Define Framework options for use in compilation
set(FRAMEWORK_DEFINITIONS "")
if (TOGGLE_FRAMEWORK_GRAPHICS)
set(FRAMEWORK_DEFINITIONS ${FRAMEWORK_DEFINITIONS} -DFRAMEWORK_GRAPHICS)
endif()
if (TOGGLE_FRAMEWORK_SOUND)
set(FRAMEWORK_DEFINITIONS ${FRAMEWORK_DEFINITIONS} -DFRAMEWORK_SOUND)
endif()
Expand Down Expand Up @@ -232,7 +236,6 @@ endif()
# OTClient source files configuration
# *****************************************************************************
set(SOURCE_FILES
framework/core/adaptativeframecounter.cpp
framework/core/application.cpp
framework/core/asyncdispatcher.cpp
framework/core/binarytree.cpp
Expand All @@ -242,7 +245,6 @@ set(SOURCE_FILES
framework/core/event.cpp
framework/core/eventdispatcher.cpp
framework/core/filestream.cpp
framework/core/graphicalapplication.cpp
framework/core/logger.cpp
framework/core/module.cpp
framework/core/modulemanager.cpp
Expand All @@ -252,32 +254,6 @@ set(SOURCE_FILES
framework/core/unzipper.h
framework/core/timer.cpp
framework/discord/discord.cpp
framework/graphics/animatedtexture.cpp
framework/graphics/apngloader.cpp
framework/graphics/bitmapfont.cpp
framework/graphics/cachedtext.cpp
framework/graphics/coordsbuffer.cpp
framework/graphics/drawpool.cpp
framework/graphics/drawpoolmanager.cpp
framework/graphics/fontmanager.cpp
framework/graphics/framebuffer.cpp
framework/graphics/graphics.cpp
framework/graphics/hardwarebuffer.cpp
framework/graphics/image.cpp
framework/graphics/painter.cpp
framework/graphics/paintershaderprogram.cpp
framework/graphics/particle.cpp
framework/graphics/particleaffector.cpp
framework/graphics/particleeffect.cpp
framework/graphics/particleemitter.cpp
framework/graphics/particlemanager.cpp
framework/graphics/particlesystem.cpp
framework/graphics/particletype.cpp
framework/graphics/shader.cpp
framework/graphics/shaderprogram.cpp
framework/graphics/texture.cpp
framework/graphics/texturemanager.cpp
framework/input/mouse.cpp
framework/luaengine/luaexception.cpp
framework/luaengine/luainterface.cpp
framework/luaengine/luaobject.cpp
Expand Down Expand Up @@ -305,29 +281,13 @@ set(SOURCE_FILES
framework/platform/unixplatform.cpp
framework/platform/win32crashhandler.cpp
framework/platform/win32platform.cpp
framework/platform/win32window.cpp
framework/platform/x11window.cpp
framework/stdext/demangle.cpp
framework/stdext/math.cpp
framework/stdext/net.cpp
framework/stdext/string.cpp
framework/stdext/time.cpp
framework/stdext/uri.cpp
framework/stdext/qrcodegen.cpp
framework/ui/uianchorlayout.cpp
framework/ui/uiboxlayout.cpp
framework/ui/uigridlayout.cpp
framework/ui/uihorizontallayout.cpp
framework/ui/uilayout.cpp
framework/ui/uimanager.cpp
framework/ui/uiparticles.cpp
framework/ui/uitextedit.cpp
framework/ui/uitranslator.cpp
framework/ui/uiverticallayout.cpp
framework/ui/uiwidget.cpp
framework/ui/uiwidgetbasestyle.cpp
framework/ui/uiwidgetimage.cpp
framework/ui/uiwidgettext.cpp
framework/util/color.cpp
framework/util/crypt.cpp

Expand Down Expand Up @@ -362,7 +322,6 @@ set(SOURCE_FILES
client/protocolgame.cpp
client/protocolgameparse.cpp
client/protocolgamesend.cpp
client/shadermanager.cpp
client/spriteappearances.cpp
client/spritemanager.cpp
client/statictext.cpp
Expand All @@ -385,6 +344,57 @@ set(SOURCE_FILES
androidmain.cpp
)

if (TOGGLE_FRAMEWORK_GRAPHICS)
set(SOURCE_FILES ${SOURCE_FILES}
framework/core/adaptativeframecounter.cpp
framework/core/graphicalapplication.cpp
framework/input/mouse.cpp
framework/graphics/animatedtexture.cpp
framework/graphics/apngloader.cpp
framework/graphics/bitmapfont.cpp
framework/graphics/cachedtext.cpp
framework/graphics/coordsbuffer.cpp
framework/graphics/drawpool.cpp
framework/graphics/drawpoolmanager.cpp
framework/graphics/fontmanager.cpp
framework/graphics/framebuffer.cpp
framework/graphics/graphics.cpp
framework/graphics/hardwarebuffer.cpp
framework/graphics/image.cpp
framework/graphics/painter.cpp
framework/graphics/paintershaderprogram.cpp
framework/graphics/particle.cpp
framework/graphics/particleaffector.cpp
framework/graphics/particleeffect.cpp
framework/graphics/particleemitter.cpp
framework/graphics/particlemanager.cpp
framework/graphics/particlesystem.cpp
framework/graphics/particletype.cpp
framework/graphics/shader.cpp
framework/graphics/shaderprogram.cpp
framework/graphics/texture.cpp
framework/graphics/texturemanager.cpp
framework/graphics/shadermanager.cpp
framework/platform/win32window.cpp
framework/platform/x11window.cpp
framework/ui/uianchorlayout.cpp
framework/ui/uiboxlayout.cpp
framework/ui/uigridlayout.cpp
framework/ui/uihorizontallayout.cpp
framework/ui/uilayout.cpp
framework/ui/uimanager.cpp
framework/ui/uiparticles.cpp
framework/ui/uitextedit.cpp
framework/ui/uitranslator.cpp
framework/ui/uiverticallayout.cpp
framework/ui/uiwidget.cpp
framework/ui/uiwidgetbasestyle.cpp
framework/ui/uiwidgetimage.cpp
framework/ui/uiwidgettext.cpp
framework/ui/uiqrcode.cpp
)
endif()

if (TOGGLE_FRAMEWORK_SOUND)
set(SOURCE_FILES ${SOURCE_FILES}
framework/sound/combinedsoundsource.cpp
Expand Down
3 changes: 2 additions & 1 deletion src/client/attachableobject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
#include <framework/core/eventdispatcher.h>
#include <framework/ui/uimanager.h>

#include "client.h"
#include "game.h"
#include "mapview.h"
#include "tile.h"
Expand Down Expand Up @@ -174,7 +175,7 @@ void AttachableObject::attachWidget(const UIWidgetPtr& widget) {
if (!widget)
return;

const auto& mapWidget = g_ui.getMapWidget();
const auto& mapWidget = g_client.getMapWidget();
if (!mapWidget)
return;

Expand Down
2 changes: 1 addition & 1 deletion src/client/attachedeffect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@
*/

#include "attachedeffect.h"
#include "shadermanager.h"
#include "gameconfig.h"
#include "lightview.h"

#include <framework/core/clock.h>
#include <framework/graphics/animatedtexture.h>
#include <framework/graphics/shadermanager.h>

AttachedEffectPtr AttachedEffect::clone()
{
Expand Down
62 changes: 59 additions & 3 deletions src/client/client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,19 @@
*/

#include "client.h"
#include <framework/core/resourcemanager.h>
#include "game.h"
#include "map.h"
#include "uimap.h"
#include "minimap.h"
#include "shadermanager.h"
#include "spriteappearances.h"
#include "spritemanager.h"

#include <framework/ui/ui.h>
#include <framework/core/eventdispatcher.h>
#include <framework/core/asyncdispatcher.h>
#include <framework/core/resourcemanager.h>
#include <framework/graphics/shadermanager.h>

Client g_client;

void Client::init(std::vector<std::string>& /*args*/)
Expand Down Expand Up @@ -59,4 +64,55 @@ void Client::terminate()
g_spriteAppearances.terminate();
g_shaders.terminate();
g_gameConfig.terminate();
}
}

void Client::drawMap()
{
if (g_game.isOnline()) {
if (!m_mapWidget)
m_mapWidget = g_ui.getRootWidget()->recursiveGetChildById("gameMapPanel")->static_self_cast<UIMap>();

m_mapWidget->drawSelf(DrawPoolType::MAP);
} else m_mapWidget = nullptr;
}

void Client::drawForgroundMap()
{
if (m_mapWidget)
m_mapWidget->drawSelf(DrawPoolType::FOREGROUND_MAP);
}

bool Client::canDraw(DrawPoolType type) const
{
switch (type) {
case DrawPoolType::FOREGROUND_MAP:
return g_game.isOnline();
default:
return false;
}
}

bool Client::canDrawUI() const
{
return g_game.isOnline();
}

bool Client::canDrawTexts() const
{
return !g_map.getStaticTexts().empty() || !g_map.getAnimatedTexts().empty();
}

bool Client::isLoadingAsyncTexture()
{
return g_game.isUsingProtobuf();
}

bool Client::isUsingProtobuf()
{
return g_game.isUsingProtobuf();
}

void Client::onLoadingAsyncTextureChanged(bool loadingAsync)
{
g_sprites.reload();
}
27 changes: 24 additions & 3 deletions src/client/client.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,33 @@

#include "global.h"

class Client
#include "uimap.h"

#include <framework/graphics/declarations.h>
#include <framework/core/graphicalapplication.h>

class Client : public ApplicationDrawEvents
{
public:
static void init(std::vector<std::string>& args);
static void terminate();
void init(std::vector<std::string>& args);
void terminate();
static void registerLuaFunctions();

void drawMap() override;
void drawForgroundMap() override;

bool canDraw(DrawPoolType type) const override;
bool canDrawUI() const override;
bool canDrawTexts() const override;
bool isLoadingAsyncTexture() override;
bool isUsingProtobuf() override;

void onLoadingAsyncTextureChanged(bool loadingAsync) override;

UIMapPtr getMapWidget() { return m_mapWidget; }

private:
UIMapPtr m_mapWidget;
};

extern Client g_client;
9 changes: 6 additions & 3 deletions src/client/creature.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
#include "localplayer.h"
#include "luavaluecasts_client.h"
#include "map.h"
#include "shadermanager.h"
#include "thingtypemanager.h"
#include "tile.h"
#include "statictext.h"
Expand All @@ -37,6 +36,7 @@
#include <framework/graphics/drawpoolmanager.h>
#include <framework/graphics/graphics.h>
#include <framework/graphics/texturemanager.h>
#include <framework/graphics/shadermanager.h>

double Creature::speedA = 0;
double Creature::speedB = 0;
Expand Down Expand Up @@ -878,7 +878,10 @@ uint16_t Creature::getStepDuration(bool ignoreDiagonal, Otc::Direction dir)

m_stepCache.duration = stepDuration + 10;
m_stepCache.walkDuration = std::min<int>(stepDuration / g_gameConfig.getSpriteSize(), DrawPool::FPS60);
m_stepCache.diagonalDuration = stepDuration * (g_game.getClientVersion() > 810 || g_gameConfig.isForcingNewWalkingFormula() ? 3 : 2);
m_stepCache.diagonalDuration = stepDuration *
(g_game.getClientVersion() > 810 || g_gameConfig.isForcingNewWalkingFormula()
? (isPlayer() ? g_gameConfig.getPlayerDiagonalWalkSpeed() : g_gameConfig.getCreatureDiagonalWalkSpeed())
: 2);
}

return ignoreDiagonal ? m_stepCache.duration : m_stepCache.getDuration(m_lastStepDirection);
Expand Down Expand Up @@ -997,4 +1000,4 @@ bool Creature::canShoot(int distance)
{
return getTile() ? getTile()->canShoot(distance) : false;
}
#endif
#endif
2 changes: 1 addition & 1 deletion src/client/declarations.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
#include <framework/ui/declarations.h>
#include "global.h"

// core
// core
class Map;
class Game;
class MapView;
Expand Down
Loading

0 comments on commit c8ae6c1

Please sign in to comment.