Skip to content

Commit

Permalink
[RDY] Cpp fmt (#1562)
Browse files Browse the repository at this point in the history
* Hand formatted changes before automatic formatting

* Break up / shorten some long lines

* Add some missing braces for clarity

* Multiline strings are merged to let clang-format split them
appropriately.

* sdl_core's frame_count changed from a C style array to std::array
which made the length checks simpler.

* Add includes and forward declairs to avoid transitive dependencies

* Remove th_gfx_font.h include from th_gfx.h - circular dependencies

* using to shorten lines in th_map.cpp

* Avoid non-portable reinterpret_cast for parcels in th_map.

* Use more constants in th_map.

* Use class initializer for th_map classes

* Add clang files to ignore list

* Add clang-format file

* Reformat all files with clang-format

Also includes some manual braces.

* Disable clang-format for backdrop.h

* Clang-format AnimView src files

* clang-format common code

* Fix anonymous struct in union warning

Anonymous structs in anonymous unions are not supported by the standard.

* Check clang-format in travis

* Bin pack parameters

* Bin pack arguments too

* Full Google style

2 space indent, no forced break on braces.

* A couple format overrides

Order of usings in config.h.in since 8 is smaller than 16.
Table layout, since 0x80 nicely fits in 8 columns.
  • Loading branch information
TheCycoONE committed Oct 6, 2019
1 parent 326e2fa commit 4a1c98a
Show file tree
Hide file tree
Showing 68 changed files with 21,287 additions and 23,028 deletions.
22 changes: 22 additions & 0 deletions .clang-format
@@ -0,0 +1,22 @@
---
Language: Cpp
BasedOnStyle: Google

MacroBlockBegin: "^\
BEGIN_EVENT_TABLE.*"
MacroBlockEnd: "^\
END_EVENT_TABLE()"

DerivePointerAlignment: false
PointerAlignment: Left

IncludeCategories:
- Regex: '^"config.h"'
Priority: 1
- Regex: '^<.*\.h>'
Priority: 2
- Regex: '^<.*'
Priority: 3
- Regex: '.*'
Priority: 4

3 changes: 3 additions & 0 deletions .gitignore
Expand Up @@ -77,6 +77,9 @@ CMakeFiles
Makefile
CMakeScripts/

# Clang tools
compile_commands.json

# This is for the CMake-generated Visual Studio project
*.vcxproj
*.vcxproj.user
Expand Down
6 changes: 5 additions & 1 deletion .travis.yml
Expand Up @@ -44,15 +44,19 @@ before_script:
# Don't ask for confirmation when using scp
- echo -e "Host armedpineapple.co.uk\n\tStrictHostKeyChecking no\n" >> ~/.ssh/config
- echo -e "Host server2.armedpineapple.co.uk\n\tStrictHostKeyChecking no\n" >> ~/.ssh/config
- cd fresh
script:
# Check if there are trailing whitespaces.
- ${TRAVIS_BUILD_DIR}/scripts/check_trailing_whitespaces.py $TRAVIS_BUILD_DIR
# Check for incorrectly encoded language files.
- ${TRAVIS_BUILD_DIR}/scripts/check_language_files_not_BOM.py $TRAVIS_BUILD_DIR/CorsixTH/Lua/languages
# Check if there are lua classes with invalid/improper declarations.
- ${TRAVIS_BUILD_DIR}/scripts/check_lua_classes.py
# Check cpp format
- cd ${TRAVIS_BUILD_DIR}
- clang-format -i CorsixTH/Src/*{.cpp,.h} AnimView/*{.cpp,.h} common/*{.cpp,.h} CorsixTH/SrcUnshared/main.cpp
- git diff --exit-code
# Build CorsixTH
- cd fresh
- make VERBOSE=1
# Validate lua files
- find $TRAVIS_BUILD_DIR -path $TRAVIS_BUILD_DIR/CorsixTH/Lua/languages -prune -o -name '*.lua' -print0 | xargs -0 luac -p --
Expand Down
22 changes: 11 additions & 11 deletions AnimView/app.cpp
Expand Up @@ -20,23 +20,23 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/

#include "config.h"
#include "app.h"
#include "config.h"
#include "frmMain.h"
#include "frmSprites.h"

IMPLEMENT_APP(ThemeHospitalAnimViewApp)

bool ThemeHospitalAnimViewApp::OnInit()
{
wxTopLevelWindow *pForm;
if(::wxMessageBox(L"Launch animation viewer? (No -> sprite viewer)", L"AnimView", wxYES_NO) == wxYES)
pForm = new frmMain;
else
pForm = new frmSprites;
bool ThemeHospitalAnimViewApp::OnInit() {
wxTopLevelWindow* pForm;
if (::wxMessageBox(L"Launch animation viewer? (No -> sprite viewer)",
L"AnimView", wxYES_NO) == wxYES)
pForm = new frmMain;
else
pForm = new frmSprites;

pForm->Show(true);
SetTopWindow(pForm);
pForm->Show(true);
SetTopWindow(pForm);

return true;
return true;
}
9 changes: 4 additions & 5 deletions AnimView/app.h
Expand Up @@ -27,19 +27,18 @@ SOFTWARE.
#include "wx/wxprec.h"

#ifdef __BORLANDC__
#pragma hdrstop
#pragma hdrstop
#endif

// for all others, include the necessary headers (this file is usually all you
// need because it includes almost all "standard" wxWidgets headers)
#ifndef WX_PRECOMP
#include "wx/wx.h"
#include "wx/wx.h"
#endif
// ----------------------------

class ThemeHospitalAnimViewApp : public wxApp
{
virtual bool OnInit();
class ThemeHospitalAnimViewApp : public wxApp {
virtual bool OnInit();
};

DECLARE_APP(ThemeHospitalAnimViewApp)
2 changes: 2 additions & 0 deletions AnimView/backdrop.h
@@ -1,4 +1,5 @@
/* XPM */
// clang-format off
static const char *const backdrop_xpm[] = {
"126 64 12 1",
"f c #695D7D",
Expand Down Expand Up @@ -78,3 +79,4 @@ static const char *const backdrop_xpm[] = {
" bfffff bfffff ",
" .f .f "
};
// clang-format on
1,214 changes: 643 additions & 571 deletions AnimView/frmMain.cpp

Large diffs are not rendered by default.

187 changes: 94 additions & 93 deletions AnimView/frmMain.h
Expand Up @@ -22,112 +22,113 @@ SOFTWARE.

#pragma once
#include "config.h"
#include <wx/frame.h>
#include <wx/button.h>
#include <wx/spinctrl.h>
#include <wx/checkbox.h>
#include <wx/textctrl.h>
#include <wx/dcclient.h>
#include <wx/frame.h>
#include <wx/listbox.h>
#include <wx/panel.h>
#include <wx/spinctrl.h>
#include <wx/textctrl.h>
#include <wx/timer.h>
#include <wx/listbox.h>
#include <wx/dcclient.h>
#include <wx/txtstrm.h>
#include "th.h"
//#include <vector>

class frmMain : public wxFrame
{
public:
frmMain();
~frmMain();
class frmMain : public wxFrame {
public:
frmMain();
~frmMain();

enum
{
ID_FIRST_ANIM = wxID_HIGHEST + 1,
ID_PREV_ANIM,
ID_ANIM_INDEX,
ID_NEXT_ANIM,
ID_LAST_ANIM,
ID_PREV_FRAME,
ID_NEXT_FRAME,
ID_PLAY_PAUSE,
ID_TIMER_ANIMATE,
ID_SEARCH_LAYER_ID,
ID_SEARCH_FRAME,
ID_SEARCH_SOUND,
ID_SEARCH_RESULTS,
ID_GHOST_0,
ID_GHOST_1,
ID_GHOST_2,
ID_GHOST_3,
ID_LOAD,
ID_BROWSE,
ID_EXPORT,
ID_DRAW_MOOD,
ID_DRAW_COORDINATES,
ID_LAYER_CHECKS, // Must be last ID
};
enum {
ID_FIRST_ANIM = wxID_HIGHEST + 1,
ID_PREV_ANIM,
ID_ANIM_INDEX,
ID_NEXT_ANIM,
ID_LAST_ANIM,
ID_PREV_FRAME,
ID_NEXT_FRAME,
ID_PLAY_PAUSE,
ID_TIMER_ANIMATE,
ID_SEARCH_LAYER_ID,
ID_SEARCH_FRAME,
ID_SEARCH_SOUND,
ID_SEARCH_RESULTS,
ID_GHOST_0,
ID_GHOST_1,
ID_GHOST_2,
ID_GHOST_3,
ID_LOAD,
ID_BROWSE,
ID_EXPORT,
ID_DRAW_MOOD,
ID_DRAW_COORDINATES,
ID_LAYER_CHECKS, // Must be last ID
};

void load();
void export_png();
void exportSpritesPage(bool bComplex, wxString sPath, wxString sFilename, wxString spPath=L"", wxString sPalette=L"MPALETTE.DAT");
//std::vector<_sprite_t> m_vSprites;
void load();
void export_png();
void exportSpritesPage(bool bComplex, wxString sPath, wxString sFilename,
wxString spPath = L"",
wxString sPalette = L"MPALETTE.DAT");
// std::vector<_sprite_t> m_vSprites;

protected:
void _onLoad(wxCommandEvent& evt);
void _onBrowse(wxCommandEvent& evt);
void _onExport(wxCommandEvent& evt);
void _onFirstAnim(wxCommandEvent& evt);
void _onPrevAnim(wxCommandEvent& evt);
void _onNextAnim(wxCommandEvent& evt);
void _onLastAnim(wxCommandEvent& evt);
void _onPrevFrame(wxCommandEvent& evt);
void _onNextFrame(wxCommandEvent& evt);
void _onPlayPause(wxCommandEvent& evt);
void _onToggleMask(wxCommandEvent& evt);
void _onToggleDrawMood(wxCommandEvent& evt);
void _onToggleDrawCoordinates(wxCommandEvent& evt);
void _onSearchLayerId(wxCommandEvent& evt);
void _onSearchFrame(wxCommandEvent& evt);
void _onSearchSoundIndex(wxCommandEvent& evt);
void _onGotoSearchResult(wxCommandEvent& evt);
void _onAnimChar(wxCommandEvent& evt);
void _onGhostFileChange(wxCommandEvent& evt);
void _onGhostIndexChange(wxSpinEvent& evt);
void _onPanelPaint(wxPaintEvent& evt);
void _onPanelClick(wxMouseEvent& evt);
void _onTimer(wxTimerEvent& evt);
protected:
void _onLoad(wxCommandEvent& evt);
void _onBrowse(wxCommandEvent& evt);
void _onExport(wxCommandEvent& evt);
void _onFirstAnim(wxCommandEvent& evt);
void _onPrevAnim(wxCommandEvent& evt);
void _onNextAnim(wxCommandEvent& evt);
void _onLastAnim(wxCommandEvent& evt);
void _onPrevFrame(wxCommandEvent& evt);
void _onNextFrame(wxCommandEvent& evt);
void _onPlayPause(wxCommandEvent& evt);
void _onToggleMask(wxCommandEvent& evt);
void _onToggleDrawMood(wxCommandEvent& evt);
void _onToggleDrawCoordinates(wxCommandEvent& evt);
void _onSearchLayerId(wxCommandEvent& evt);
void _onSearchFrame(wxCommandEvent& evt);
void _onSearchSoundIndex(wxCommandEvent& evt);
void _onGotoSearchResult(wxCommandEvent& evt);
void _onAnimChar(wxCommandEvent& evt);
void _onGhostFileChange(wxCommandEvent& evt);
void _onGhostIndexChange(wxSpinEvent& evt);
void _onPanelPaint(wxPaintEvent& evt);
void _onPanelClick(wxMouseEvent& evt);
void _onTimer(wxTimerEvent& evt);

void _onAnimChange(size_t iIndex);
void _onAnimChange(size_t iIndex);

void _drawCoordinates(wxPaintDC& DC, int i, int j);
wxString _getCaseSensitivePath(const wxString& sInsensitivePathPart, const wxString& sPath);
void _drawCoordinates(wxPaintDC& DC, int i, int j);
wxString _getCaseSensitivePath(const wxString& sInsensitivePathPart,
const wxString& sPath);

THAnimations m_oAnims;
THLayerMask m_mskLayers;
wxImage m_imgBackground;
wxTimer m_tmrAnimate;
size_t m_iCurrentAnim;
size_t m_iCurrentFrame;
int m_iGhostFile;
int m_iGhostIndex;
int m_iMoodDrawX;
int m_iMoodDrawY;
bool m_bPlayingAnimation;
bool m_bDrawMood;
bool m_bDrawCoordinates;
THAnimations m_oAnims;
THLayerMask m_mskLayers;
wxImage m_imgBackground;
wxTimer m_tmrAnimate;
size_t m_iCurrentAnim;
size_t m_iCurrentFrame;
int m_iGhostFile;
int m_iGhostIndex;
int m_iMoodDrawX;
int m_iMoodDrawY;
bool m_bPlayingAnimation;
bool m_bDrawMood;
bool m_bDrawCoordinates;

wxButton* m_btnPlayPause;
wxButton* m_btnExport;
wxTextCtrl* m_txtTHPath;
wxTextCtrl* m_txtAnimIndex;
wxTextCtrl* m_txtAnimCount;
wxTextCtrl* m_txtFrameIndex;
wxTextCtrl* m_txtFrameCount;
wxTextCtrl* m_txtFrameFlags[2];
wxTextCtrl* m_txtMoodPosition[2];
wxCheckBox* m_chkFrameFlags[16];
wxListBox* m_lstSearchResults;
wxPanel* m_panFrame;
DECLARE_EVENT_TABLE()
wxButton* m_btnPlayPause;
wxButton* m_btnExport;
wxTextCtrl* m_txtTHPath;
wxTextCtrl* m_txtAnimIndex;
wxTextCtrl* m_txtAnimCount;
wxTextCtrl* m_txtFrameIndex;
wxTextCtrl* m_txtFrameCount;
wxTextCtrl* m_txtFrameFlags[2];
wxTextCtrl* m_txtMoodPosition[2];
wxCheckBox* m_chkFrameFlags[16];
wxListBox* m_lstSearchResults;
wxPanel* m_panFrame;
DECLARE_EVENT_TABLE()
};

0 comments on commit 4a1c98a

Please sign in to comment.