Skip to content
Permalink
Browse files

[RDY] Cpp fmt (#1562)

* 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 4a1c98a716286f44f8e95af4374d3816ae358400
Showing with 21,287 additions and 23,028 deletions.
  1. +22 −0 .clang-format
  2. +3 −0 .gitignore
  3. +5 −1 .travis.yml
  4. +11 −11 AnimView/app.cpp
  5. +4 −5 AnimView/app.h
  6. +2 −0 AnimView/backdrop.h
  7. +643 −571 AnimView/frmMain.cpp
  8. +94 −93 AnimView/frmMain.h
  9. +156 −150 AnimView/frmSprites.cpp
  10. +49 −49 AnimView/frmSprites.h
  11. +385 −518 AnimView/th.cpp
  12. +171 −175 AnimView/th.h
  13. +262 −262 CorsixTH/Src/bootstrap.cpp
  14. +3 −3 CorsixTH/Src/bootstrap.h
  15. +8 −6 CorsixTH/Src/config.h.in
  16. +4 −4 CorsixTH/Src/cp437_table.h
  17. +2,773 −3,278 CorsixTH/Src/cp936_table.h
  18. +454 −473 CorsixTH/Src/iso_fs.cpp
  19. +111 −110 CorsixTH/Src/iso_fs.h
  20. +8 −19 CorsixTH/Src/lua.hpp
  21. +42 −47 CorsixTH/Src/lua_rnc.cpp
  22. +1 −1 CorsixTH/Src/lua_rnc.h
  23. +4 −4 CorsixTH/Src/lua_sdl.h
  24. +104 −106 CorsixTH/Src/main.cpp
  25. +5 −5 CorsixTH/Src/main.h
  26. +1,157 −1,291 CorsixTH/Src/persist_lua.cpp
  27. +106 −124 CorsixTH/Src/persist_lua.h
  28. +46 −60 CorsixTH/Src/random.c
  29. +206 −255 CorsixTH/Src/run_length_encoder.cpp
  30. +87 −89 CorsixTH/Src/run_length_encoder.h
  31. +239 −269 CorsixTH/Src/sdl_audio.cpp
  32. +307 −343 CorsixTH/Src/sdl_core.cpp
  33. +19 −23 CorsixTH/Src/sdl_wm.cpp
  34. +139 −182 CorsixTH/Src/th.cpp
  35. +70 −73 CorsixTH/Src/th.h
  36. +1,576 −1,661 CorsixTH/Src/th_gfx.cpp
  37. +516 −514 CorsixTH/Src/th_gfx.h
  38. +692 −755 CorsixTH/Src/th_gfx_font.cpp
  39. +270 −267 CorsixTH/Src/th_gfx_font.h
  40. +1,072 −1,248 CorsixTH/Src/th_gfx_sdl.cpp
  41. +575 −580 CorsixTH/Src/th_gfx_sdl.h
  42. +277 −325 CorsixTH/Src/th_lua.cpp
  43. +198 −195 CorsixTH/Src/th_lua.h
  44. +571 −579 CorsixTH/Src/th_lua_anims.cpp
  45. +773 −821 CorsixTH/Src/th_lua_gfx.cpp
  46. +156 −159 CorsixTH/Src/th_lua_internal.h
  47. +85 −99 CorsixTH/Src/th_lua_iso.cpp
  48. +50 −59 CorsixTH/Src/th_lua_lfs_ext.cpp
  49. +836 −861 CorsixTH/Src/th_lua_map.cpp
  50. +85 −99 CorsixTH/Src/th_lua_movie.cpp
  51. +225 −246 CorsixTH/Src/th_lua_sound.cpp
  52. +534 −606 CorsixTH/Src/th_lua_strings.cpp
  53. +127 −131 CorsixTH/Src/th_lua_ui.cpp
  54. +1,510 −1,526 CorsixTH/Src/th_map.cpp
  55. +502 −497 CorsixTH/Src/th_map.h
  56. +144 −161 CorsixTH/Src/th_map_overlays.cpp
  57. +52 −57 CorsixTH/Src/th_map_overlays.h
  58. +794 −906 CorsixTH/Src/th_movie.cpp
  59. +344 −307 CorsixTH/Src/th_movie.h
  60. +513 −509 CorsixTH/Src/th_pathfind.cpp
  61. +213 −219 CorsixTH/Src/th_pathfind.h
  62. +216 −227 CorsixTH/Src/th_sound.cpp
  63. +77 −77 CorsixTH/Src/th_sound.h
  64. +269 −349 CorsixTH/Src/xmi2mid.cpp
  65. +9 −10 CorsixTH/Src/xmi2mid.h
  66. +76 −83 CorsixTH/SrcUnshared/main.cpp
  67. +242 −286 common/rnc.cpp
  68. +8 −9 common/rnc.h
@@ -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

@@ -77,6 +77,9 @@ CMakeFiles
Makefile
CMakeScripts/

# Clang tools
compile_commands.json

# This is for the CMake-generated Visual Studio project
*.vcxproj
*.vcxproj.user
@@ -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 --
@@ -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;
}
@@ -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)
@@ -1,4 +1,5 @@
/* XPM */
// clang-format off
static const char *const backdrop_xpm[] = {
"126 64 12 1",
"f c #695D7D",
@@ -78,3 +79,4 @@ static const char *const backdrop_xpm[] = {
" bfffff bfffff ",
" .f .f "
};
// clang-format on

Large diffs are not rendered by default.

@@ -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.
You can’t perform that action at this time.