Skip to content

Commit

Permalink
- Fix some warnings
Browse files Browse the repository at this point in the history
- Statically link in both Windows & Linux
- Update to use modern CMake

Signed-off-by: minneyar <[email protected]>
  • Loading branch information
pjreed authored and minneyar committed Apr 20, 2022
1 parent 526e64e commit b1d30ad
Show file tree
Hide file tree
Showing 10 changed files with 71 additions and 56 deletions.
55 changes: 36 additions & 19 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,32 +1,49 @@
cmake_minimum_required (VERSION 2.8.11)
project (xenoprobes)

add_definitions(-std=c++11)
cmake_minimum_required (VERSION 3.8)
project (xenoprobes
VERSION 1.0.0
LANGUAGES CXX)

find_package (Threads)
find_package (Boost COMPONENTS program_options system REQUIRED)
include_directories(${Boost_INCLUDE_DIR})
set(Boost_USE_STATIC_LIBS ON)
set(Boost_USE_MULTITHREADED ON)
find_package (Boost COMPONENTS filesystem program_options system REQUIRED)

if(MSVC)
add_compile_options(
$<$<CONFIG:>:/MT> #---------|
$<$<CONFIG:Debug>:/MTd> #---|-- Statically link the runtime libraries
$<$<CONFIG:Release>:/MT> #--|
)
endif()

add_executable(${PROJECT_NAME})

set (SOURCE_FILES
if (MSVC)
set_target_properties(${PROJECT_NAME} PROPERTIES
MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>"
CXX_STANDARD 14
)
else()
set_property(TARGET ${PROJECT_NAME} PROPERTY CXX_STANDARD 14)
endif()

target_sources(${PROJECT_NAME} PRIVATE
src/main.cpp
src/ore.cpp
src/ore.h
src/probe_arrangement.cpp
src/probe_arrangement.h
src/probe.cpp
src/probe.h
src/probe_optimizer.cpp
src/probe_optimizer.h
src/site.cpp
src/site.h
src/site_list.cpp
src/site_list.h
src/solution.cpp
src/solution.h
src/semaphore.cpp
src/semaphore.h)

add_executable (xenoprobes ${SOURCE_FILES})

target_link_libraries (xenoprobes ${Boost_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT})
)
target_link_libraries (${PROJECT_NAME}
PRIVATE
Boost::filesystem
Boost::program_options
Boost::system
Threads::Threads
$<IF:$<BOOL:MSVC>,,-static>
)

2 changes: 0 additions & 2 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -166,8 +166,6 @@ void doWin32Init()

int main(int argc, const char** argv)
{
clog << PACKAGE_STRING << endl;

#ifdef __MINGW32__
doWin32Init();
#endif
Expand Down
20 changes: 10 additions & 10 deletions src/probe_arrangement.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,12 @@ const std::vector<Probe> ProbeArrangement::PROBE_VALUES = {
Probe(Probe::Type::Storage , 0.1, 0.1, 1.0)
};

void ProbeArrangement::resize(unsigned long size) {
void ProbeArrangement::resize(size_t size) {
std::cout << "Resizing to " << size << std::endl;
probes_.resize(size);
}

void ProbeArrangement::setProbeAt(int index, const Probe::Type &type) {
void ProbeArrangement::setProbeAt(size_t index, const Probe::Type &type) {
std::cout << "Setting probe at " << index << " to " << type << std::endl;
probes_[index] = type;
}
Expand All @@ -68,7 +68,7 @@ void ProbeArrangement::seedMT(std::seed_seq& seed) {
mt.seed(seed);
}

Probe::Type ProbeArrangement::getProbeAt(int index) const {
Probe::Type ProbeArrangement::getProbeAt(size_t index) const {
return Probe::Type::Mining3;
}

Expand All @@ -86,9 +86,9 @@ void ProbeArrangement::mutate(double probability) {
}

double ProbeArrangement::evaluate() const {
long totalProd = 0;
long totalRev = 0;
long totalStorage = 6000;
double totalProd = 0;
double totalRev = 0;
double totalStorage = 6000;
for (size_t i = 0; i < ProbeOptimizer::getSites().size(); ++i) {
totalProd += getProduction(i);
totalRev += getRevenue(i);
Expand Down Expand Up @@ -143,14 +143,14 @@ void ProbeArrangement::setRevenueWeight(double revenue_weight) {
revenue_weight_ = revenue_weight;
}

unsigned long ProbeArrangement::getSize() const {
size_t ProbeArrangement::getSize() const {
return probes_.size();
}

void ProbeArrangement::printTotals() const {
long totalProd = 0;
long totalRev = 0;
long totalStorage = 6000;
double totalProd = 0;
double totalRev = 0;
double totalStorage = 6000;
// keep track of which ores have a mining probe on them
// TODO: figure out how different probes affect ore extraction
std::set<int> minedOres;
Expand Down
8 changes: 4 additions & 4 deletions src/probe_arrangement.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@

class ProbeArrangement {
public:
void resize(unsigned long size);
void setProbeAt(int index, const Probe::Type& type);
Probe::Type getProbeAt(int index) const;
void resize(size_t size);
void setProbeAt(size_t index, const Probe::Type& type);
Probe::Type getProbeAt(size_t index) const;

void mutate(double probability);

Expand All @@ -32,7 +32,7 @@ class ProbeArrangement {
double getRevenueWeight() const;
void setRevenueWeight(double revenue_weight);

unsigned long getSize() const;
size_t getSize() const;

friend bool operator==(const ProbeArrangement& l, const ProbeArrangement& r);

Expand Down
2 changes: 1 addition & 1 deletion src/probe_optimizer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#include <map>
#include <iostream>
#include <fstream>
#include <bits/stl_algo.h>
// #include <bits/stl_algo.h>
#include <boost/algorithm/string/split.hpp>
#include <boost/algorithm/string/trim.hpp>
#include <iomanip>
Expand Down
2 changes: 1 addition & 1 deletion src/probe_optimizer.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ class ProbeOptimizer {
for (const auto& item : inventory_) {
++histoInv[item];
}
for (int i = 0; i < setup_.getSize(); i++) {
for (size_t i = 0; i < setup_.getSize(); i++) {
++histoSetup[setup_.getProbeAt(i)];
}
return histoInv == histoSetup;
Expand Down
4 changes: 2 additions & 2 deletions src/site.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,11 @@ void Site::setSightseeing(int i) {
sightseeing_ = i;
}

void Site::addNeighbor(int i) {
void Site::addNeighbor(size_t i) {
neighbors_.push_back(i);
}

std::vector<int> Site::getNeighbors() const {
std::vector<size_t> Site::getNeighbors() const {
return neighbors_;
}

Expand Down
6 changes: 3 additions & 3 deletions src/site.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ class Site {
int getSightseeing() const;
void setSightseeing(int);

void addNeighbor(int);
std::vector<int> getNeighbors() const;
void addNeighbor(size_t);
std::vector<size_t> getNeighbors() const;
void addOre(int);
std::vector<int> getOres() const;

Expand All @@ -29,7 +29,7 @@ class Site {
int production_ = 0;
int revenue_ = 0;
int sightseeing_ = 0;
std::vector<int> neighbors_;
std::vector<size_t> neighbors_;
std::vector<int> ores_;
};

Expand Down
14 changes: 7 additions & 7 deletions src/site_list.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
#include "site_list.h"
#include "probe_optimizer.h"

void SiteList::addNeighborToSite(int site_index, int neighbor_index) {
void SiteList::addNeighborToSite(size_t site_index, size_t neighbor_index) {
sites_[site_index].addNeighbor(neighbor_index);
sites_[neighbor_index].addNeighbor(site_index);
}
Expand Down Expand Up @@ -84,7 +84,7 @@ void SiteList::loadSites() {

}

int SiteList::findIndexForSiteName(int name) const {
long SiteList::findIndexForSiteName(int name) const {
for (int i=0; i< sites_.size(); ++i) {
if (sites_[i].getName() == name) {
return i;
Expand All @@ -93,11 +93,11 @@ int SiteList::findIndexForSiteName(int name) const {
return -1;
}

Site SiteList::getSite(int index) const {
Site SiteList::getSite(size_t index) const {
return sites_[index];
}

int SiteList::findIndexForOreName(const std::string& name) const {
long SiteList::findIndexForOreName(const std::string& name) const {
for (int i = 0; i < ores_.size(); i++) {
if (ores_[i].getName() == name) {
return i;
Expand All @@ -110,14 +110,14 @@ void SiteList::clear() {
sites_.clear();
}

unsigned long SiteList::size() const {
size_t SiteList::size() const {
return sites_.size();
}

Ore SiteList::getOreByIndex(int index) const {
Ore SiteList::getOreByIndex(size_t index) const {
return ores_[index];
}

unsigned long SiteList::getOreCount() const {
size_t SiteList::getOreCount() const {
return ores_.size();
}
14 changes: 7 additions & 7 deletions src/site_list.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,16 @@

class SiteList {
public:
void addNeighborToSite(int site_index, int neighbor_index);
void addNeighborToSite(size_t site_index, size_t neighbor_index);
void loadSites();
int findIndexForSiteName(int name) const;
Site getSite(int index) const;
int findIndexForOreName(const std::string& name) const;
Ore getOreByIndex(int index) const;
long findIndexForSiteName(int name) const;
Site getSite(size_t index) const;
long findIndexForOreName(const std::string& name) const;
Ore getOreByIndex(size_t index) const;
void clear();

unsigned long size() const;
unsigned long getOreCount() const;
size_t size() const;
size_t getOreCount() const;

private:
std::vector<Site> sites_;
Expand Down

0 comments on commit b1d30ad

Please sign in to comment.