Permalink
Browse files

Moving headers into the root. Fixing polygon detecting algorithm.

- Removing emty *.cpp files
- Adding exceptions when an edge index is beyond the limit
- Adding the cmake file for finding the old LibKDEGames
- Removing inline attributes.
  • Loading branch information...
1 parent 0ff2f1b commit 19ea385174d0503ef2f1266a8c8c16bcae4ed05a @Ignotus committed Aug 30, 2012
View
@@ -1,6 +1,11 @@
CMAKE_MINIMUM_REQUIRED (VERSION 2.6)
PROJECT (kdots)
+SET (CMAKE_MODULE_PATH
+ ${CMAKE_MODULE_PATH}
+ ${CMAKE_CURRENT_SOURCE_DIR}/cmake
+)
+
FIND_PACKAGE (Qt4 REQUIRED)
FIND_PACKAGE (KDE4 REQUIRED)
@@ -10,18 +15,10 @@ IF (KDEGAMES_FOUND)
ADD_DEFINITIONS(-DOLD_LIBKDEGAMES)
ELSE (KDEGAMES_FOUND)
FIND_PACKAGE (KDEGames REQUIRED)
+ MESSAGE(STATUS "Found KDEGames")
ADD_DEFINITIONS (-DNEW_LIBKDEGAMES)
ENDIF (KDEGAMES_FOUND)
-#IF (KDEGAMES_LIBRARY)
-# MESSAGE(STATUS "FOUND ${KDEGAMES_LIBRARY}")
-# ADD_DEFINITIONS (-DNEW_LIBKDEGAMES)
-#ELSE (KDEGAMES_LIBRARY)
-# MESSAGE(STATUS "NOT FOUND")
-# FIND_PACKAGE (LibKDEGames REQUIRED)
-# ADD_DEFINITIONS (-DOLD_LIBKDEGAMES)
-#ENDIF (KDEGAMES_LIBRARY)
-
INCLUDE (KDE4Defaults)
OPTION (KDE4_BUILD_TESTS "Enable test units" OFF)
@@ -47,7 +44,7 @@ INCLUDE_DIRECTORIES (
${QT_INCLUDES}
)
-SET (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++0x")
+SET (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++0x -fexceptions")
SET (PLUGIN_BUILD_DIR ${CMAKE_CURRENT_BINARY_DIR}/plugins)
SET (KDOTS_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR})
@@ -60,7 +57,6 @@ ENDIF (UNIX)
SET (SRCS
brushcombo.cpp
- graphpoint.cpp
graph.cpp
dottable.cpp
stepqueue.cpp
@@ -69,7 +65,6 @@ SET (SRCS
newgamedialog.cpp
mainwindow.cpp
polygonfinder.cpp
- polygon.cpp
plugincontainer.cpp
pluginmanagerwidget.cpp
gameconfig.cpp
@@ -79,24 +74,24 @@ SET (SRCS
)
SET (HEADERS
- include/brushcombo.hpp
- include/graphpoint.hpp
- include/graph.hpp
- include/dottable.hpp
- include/stepqueue.hpp
- include/tablewidget.hpp
- include/edgelist.hpp
- include/point.hpp
- include/newgamedialog.hpp
- include/newgamewidget.hpp
- include/mainwindow.hpp
- include/constants.hpp
- include/polygonfinder.hpp
- include/polygon.hpp
- include/plugincontainer.hpp
- include/pluginmanagerwidget.hpp
- include/gameconfig.hpp
- include/brushcombodelegate.hpp
+ brushcombo.hpp
+ graphpoint.hpp
+ graph.hpp
+ dottable.hpp
+ stepqueue.hpp
+ tablewidget.hpp
+ edgelist.hpp
+ point.hpp
+ newgamedialog.hpp
+ newgamewidget.hpp
+ mainwindow.hpp
+ constants.hpp
+ polygonfinder.hpp
+ polygon.hpp
+ plugincontainer.hpp
+ pluginmanagerwidget.hpp
+ gameconfig.hpp
+ brushcombodelegate.hpp
)
SET (INTERFACE_HEAD
@@ -170,4 +165,4 @@ ADD_CUSTOM_TARGET (uninstall
ADD_SUBDIRECTORY (plugins)
#INCLUDE (MacroOptionalAddSubdirectory)
-#MACRO_OPTIONAL_ADD_SUBDIRECTORY (po)
+#MACRO_OPTIONAL_ADD_SUBDIRECTORY (po)
View
@@ -62,4 +62,4 @@ namespace KDots
}
}
-#include "include/brushcombo.moc"
+#include "brushcombo.moc"
File renamed without changes.
View
@@ -109,4 +109,4 @@ namespace KDots
}
}
-#include "include/brushcombodelegate.moc"
+#include "brushcombodelegate.moc"
File renamed without changes.
@@ -0,0 +1,49 @@
+# - Try to find the kdegames library
+# Once done this will define
+#
+# KDEGAMES_FOUND - system has the kdegames library
+# KDEGAMES_INCLUDE_DIRS - a list of the relevant libkdegames include dirs. Allows the use of forwarding header, e.g. #include <KGameDifficulty>
+# KDEGAMES_INCLUDE_DIR - the kdegames include directory
+# KDEGAMES_LIBRARY - Link this to use the kdegames library
+#
+include(CheckLibraryExists)
+
+if (KDEGAMES_INCLUDE_DIR AND KDEGAMES_LIBRARY)
+ # in cache already
+ SET(KDEGAMES_FOUND TRUE)
+
+else (KDEGAMES_INCLUDE_DIR AND KDEGAMES_LIBRARY)
+
+ # reset vars
+ set(KDEGAMES_INCLUDE_DIRS)
+ set(KDEGAMES_INCLUDE_DIR)
+ set(KDEGAMES_LIBRARY)
+ FIND_PATH(KDEGAMES_INCLUDE_DIR kgamedifficulty.h
+ ${INCLUDE_INSTALL_DIR}
+ ${KDE4_INCLUDE_DIR}
+ ${GNUWIN32_DIR}/include
+ )
+ set(KDEGAMES_INCLUDE_DIR ${KDEGAMES_INCLUDE_DIR})
+
+ set(CMAKE_LIBRARY_PATH ${LIB_INSTALL_DIR})
+ find_library(KDEGAMES_LIBRARY NAMES kdegames
+ PATHS
+ ${LIB_INSTALL_DIR}
+ ${KDE4_LIB_DIR}
+ ${GNUWIN32_DIR}/lib
+ )
+ set(KDEGAMES_LIBRARY ${KDEGAMES_LIBRARY})
+
+ include(FindPackageHandleStandardArgs)
+ FIND_PACKAGE_HANDLE_STANDARD_ARGS(KDEGAMES DEFAULT_MSG KDEGAMES_INCLUDE_DIR KDEGAMES_LIBRARY )
+
+ MARK_AS_ADVANCED(KDEGAMES_INCLUDE_DIR KDEGAMES_LIBRARY)
+ENDIF(KDEGAMES_INCLUDE_DIR AND KDEGAMES_LIBRARY)
+
+#The ${KDEGAMES_INCLUDE_DIR}/KDE addition is for the forwarding includes
+IF(NOT KDEGAMES_INCLUDE_DIRS)
+ SET(KDEGAMES_INCLUDE_DIRS ${KDEGAMES_INCLUDE_DIR} ${KDEGAMES_INCLUDE_DIR}/KDE ${KDEGAMES_INCLUDE_DIR}/KDE/KGame)
+ MARK_AS_ADVANCED(KDEGAMES_INCLUDE_DIRS)
+ENDIF(NOT KDEGAMES_INCLUDE_DIRS)
+
+
@@ -27,6 +27,7 @@
#define KDOTS_CONSTANTS_HPP
#include <QString>
#include <kdemacros.h>
+#include "point.hpp"
#ifndef KDOTS_EXPORT
# if defined(MAKE_KDOTS_LIB)
// We are building this library
@@ -55,10 +56,12 @@ namespace KDots
FIRST,
SECOND
};
+
+ const int DIRECTION_COUNT = 8;
- const int GRAPH_DX[8] = {0, 1, 1, 1, 0, -1, -1, -1};
- const int GRAPH_DY[8] = {1, 1, 0, -1, -1, -1, 0, 1};
-
+ const int GRAPH_DX[DIRECTION_COUNT] = {0, 1, 1, 1, 0, -1, -1, -1};
+ const int GRAPH_DY[DIRECTION_COUNT] = {1, 1, 0, -1, -1, -1, 0, 1};
+
const QString PLUGIN_SUFFIX = "kdots_";
}
View
@@ -26,6 +26,7 @@
#include "dottable.hpp"
#include <KMessageBox>
#include <KLocalizedString>
+#include <KDebug>
#include "graph.hpp"
#include "polygonfinder.hpp"
#include "stepqueue.hpp"
@@ -95,6 +96,9 @@ namespace KDots
++itr;
continue;
}
+
+ if (itr->x () == point.x ())
+ return true;
const Point& prevPoint = getPrevPoint (polygon, itr);
const Point& nextPoint = getNextPoint (polygon, shift, itr);
@@ -107,12 +111,6 @@ namespace KDots
return i % 2;
}
-
- int doubleTriangleArea (const Point& a, const Point& b, const Point& c)
- {
- return std::abs ((b.x () - a.x ()) * (c.y () - a.y ())
- - (c.x () - a.x ()) * (b.y () - a.y ()));
- }
}
void DotTable::pushPoint (const Point& point)
@@ -225,6 +223,62 @@ namespace KDots
for (const Point& point : points)
pushPoint (point);
}
+
+ namespace
+ {
+ Polygon::iterator next (Polygon& polygon, Polygon::iterator current)
+ {
+ if (current == --polygon.end ())
+ return polygon.begin ();
+ else
+ return ++current;
+ }
+
+ int sqrLength (const Point& first, const Point& second)
+ {
+ const int dx = second.x () - first.x ();
+ const int dy = second.y () - first.y ();
+ return dx * dx + dy * dy;
+ }
+ }
+
+ void DotTable::resizePolygon (Polygon_ptr polygon)
+ {
+ const Owner current = m_steps->getCurrentOwner ();
+
+ for (Polygon::iterator itr = polygon->begin (), endItr = polygon->end ();
+ itr != endItr; ++itr)
+ {
+ for (int i = 0; i < DIRECTION_COUNT; ++i)
+ {
+ const int tempx = itr->x () + GRAPH_DX[i];
+ const int tempy = itr->y () + GRAPH_DY[i];
+
+ if (tempx < 0 || tempy < 0
+ || static_cast<std::size_t> (tempx) >= m_graph->width ()
+ || static_cast<std::size_t> (tempy) >= m_graph->height ())
+ continue;
+
+ const Point newPoint (tempx, tempy);
+ const GraphPoint& graphPoint = (*m_graph)[newPoint];
+
+ if (graphPoint.owner () != current || graphPoint.isCaptured ())
+ continue;
+
+ Polygon::iterator nextItr = next (*polygon, itr);
+
+ const int sum = sqrLength (newPoint, *itr) + sqrLength (newPoint, *nextItr);
+
+ if (sum != 2 && sum != 3)
+ continue;
+
+ if (isInPolygon (polygon, newPoint))
+ continue;
+
+ polygon->insert (nextItr, newPoint);
+ }
+ }
+ }
void DotTable::drawPolygon (PolyList polygons)
{
@@ -233,6 +287,8 @@ namespace KDots
if (!polygon->isFilled ())
continue;
+ resizePolygon (polygon);
+
polygon->setOwner (m_steps->getCurrentOwner ());
m_polygons.push_back (polygon);
@@ -247,4 +303,4 @@ namespace KDots
}
}
-#include "include/dottable.moc"
+#include "dottable.moc"
@@ -49,17 +49,17 @@ namespace KDots
void pushPoint (const Point& point);
- inline std::vector<Polygon_ptr> polygons ()
+ std::vector<Polygon_ptr> polygons ()
{
return m_polygons;
}
- inline Graph& graph () const
+ Graph& graph () const
{
return *m_graph;
}
- inline std::shared_ptr<StepQueue> stepQueue ()
+ std::shared_ptr<StepQueue> stepQueue ()
{
return m_steps;
}
@@ -69,6 +69,7 @@ namespace KDots
void nextPlayer (const Point& lastPoint);
private:
void drawPolygon (PolyList polygons);
+ void resizePolygon (Polygon_ptr polygon);
void continueStep ();
};
@@ -25,6 +25,7 @@
*/
#ifndef KDOTS_EDGELIST_HPP
#define KDOTS_EDGELIST_HPP
+#include <stdexcept>
#include "point.hpp"
namespace KDots
@@ -35,11 +36,11 @@ namespace KDots
int m_count;
Point m_pointList[SIZE];
public:
- inline EdgeList()
+ EdgeList()
: m_count (0)
{}
- inline bool addEdge (const Point& point)
+ bool addEdge (const Point& point)
{
if (m_count == SIZE || hasPoint (point))
return false;
@@ -48,12 +49,12 @@ namespace KDots
return true;
}
- inline int size () const
+ int size () const
{
return m_count;
}
- inline bool hasPoint (const Point& point)
+ bool hasPoint (const Point& point)
{
for (int i = 0; i < m_count; ++i)
{
@@ -64,18 +65,19 @@ namespace KDots
return false;
}
- inline Point& operator[] (int index)
+ Point& operator[] (int index)
{
return const_cast<EdgeList<SIZE>&> (static_cast<const EdgeList<SIZE>&> (*this) [index]);
}
- inline const Point& operator[] (int index) const
+ const Point& operator[] (int index) const
{
- Point def;
- return index >= 0 && index < m_count ? m_pointList[index] : def;
+ if (index >= 0 && index < m_count)
+ throw std::runtime_error ("beyond the limit of the array");
+ return m_pointList[index];
}
- inline bool removeEdge (const Point& toPoint)
+ bool removeEdge (const Point& toPoint)
{
for (int i = 0; i < m_count; ++i)
{
File renamed without changes.
Oops, something went wrong.

0 comments on commit 19ea385

Please sign in to comment.