Skip to content

Commit

Permalink
make it buildable
Browse files Browse the repository at this point in the history
  • Loading branch information
fl4shk committed Nov 6, 2022
1 parent 43c532f commit 331c4d0
Show file tree
Hide file tree
Showing 6 changed files with 311 additions and 10 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
*.o
*.a
*.d
*.P
*.elf
*.sav*
*.ss*
Expand All @@ -9,3 +10,5 @@
tags
types_*.taghl
*.ignore
wfc
wfc_debug
182 changes: 182 additions & 0 deletions GNUmakefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,182 @@
# These directories specify where source code files are located.
# Edit these variables if more directories are needed.
# Separate each entry by spaces.


SHARED_SRC_DIRS:=src \

CXX_DIRS:=$(SHARED_SRC_DIRS)
# End of source directories


# Whether or not to do debugging stuff
#DEBUG:=yeah do debug

DEBUG_OPTIMIZATION_LEVEL:=-Og
REGULAR_OPTIMIZATION_LEVEL:=-O2


ALWAYS_DEBUG_SUFFIX:=_debug
ifdef DEBUG
DEBUG_SUFFIX:=$(ALWAYS_DEBUG_SUFFIX)
endif

# This is the name of the output file. Change this if needed!
PROJ:=$(shell basename $(CURDIR))$(DEBUG_SUFFIX)

# This is used for do_asmouts
#VERBOSE_ASM_FLAG:=-fverbose-asm

# Compilers and initial compiler flags
CXX:=$(PREFIX)g++
CXX_FLAGS:=$(CXX_FLAGS) -std=c++20 -fcoroutines -fmodules-ts -Wall

ifdef DEBUG
CXX_FLAGS:=$(CXX_FLAGS) -DDEBUG=1
endif
OBJDUMP:=$(PREFIX)objdump


LD:=$(CXX)

# Initial linker flags
LD_FLAGS:=$(LD_FLAGS) -lm



ifdef DEBUG
EXTRA_DEBUG_FLAGS:=-g
DEBUG_FLAGS:=-gdwarf-3 $(EXTRA_DEBUG_FLAGS)
EXTRA_LD_FLAGS:=$(DEBUG_FLAGS)
OPTIMIZATION_LEVEL:=$(DEBUG_OPTIMIZATION_LEVEL)
else
OPTIMIZATION_LEVEL:=$(REGULAR_OPTIMIZATION_LEVEL)
endif




FINAL_BASE_FLAGS:=$(OPTIMIZATION_LEVEL) \
$(EXTRA_BASE_FLAGS) $(EXTRA_DEBUG_FLAGS)

# Final compiler and linker flags
CXX_FLAGS:=$(CXX_FLAGS) $(FINAL_BASE_FLAGS)
LD_FLAGS:=$(LD_FLAGS) $(EXTRA_LD_FLAGS) $(COMMON_LD_FLAGS)




# Generated directories
OBJDIR:=objs$(DEBUG_SUFFIX)
ASMOUTDIR:=asmouts$(DEBUG_SUFFIX)
DEPDIR:=deps$(DEBUG_SUFFIX)




CXX_SOURCES := $(foreach DIR,$(CXX_DIRS),$(wildcard $(DIR)/*.cpp))
CXX_OFILES := $(CXX_SOURCES:%.cpp=$(OBJDIR)/%.o)
CXX_PFILES := $(CXX_SOURCES:%.cpp=$(DEPDIR)/%.P)

# Assembly source code generated by gcc/g++
CXX_ASMOUTS := $(CXX_SOURCES:%.cpp=$(ASMOUTDIR)/%.s)



# Compiler-generated files
# OFILES are object code files (extension .o)
OFILES:=$(CXX_OFILES)
# PFILES are used for automatic dependency generation
PFILES:=$(CXX_PFILES)
ASMOUTS:=$(CXX_ASMOUTS)


.PHONY : all
all : all_pre $(OFILES)
$(LD) $(OFILES) -o $(PROJ) $(LD_FLAGS)


# all_objs is ENTIRELY optional
.PHONY : all_objs
all_objs : all_pre $(OFILES)
@#


.PHONY : do_asmouts
do_asmouts : all_pre all_pre_asmout $(ASMOUTS)
@#


.PHONY : all_pre
all_pre :
mkdir -p $(OBJDIR) $(DEPDIR)
@for ofile in $(OFILES); \
do \
mkdir -p $$(dirname $$ofile); \
done
@for pfile in $(PFILES); \
do \
mkdir -p $$(dirname $$pfile); \
done



.PHONY : all_pre_asmout
all_pre_asmout :
mkdir -p $(ASMOUTDIR)
@for asmout in $(ASMOUTS); \
do \
mkdir -p $$(dirname $$asmout); \
done


# Here's where things get really messy.
$(CXX_OFILES) : $(OBJDIR)/%.o : %.cpp
@echo $@" was updated or has no object file. (Re)Compiling...."
$(CXX) $(CXX_FLAGS) -MMD -c $< -o $@
@cp $(OBJDIR)/$*.d $(DEPDIR)/$*.P
@rm -f $(OBJDIR)/$*.d



# Here we have stuff for outputting assembly source code instead of an object file.
$(CXX_ASMOUTS) : $(ASMOUTDIR)/%.s : %.cpp
$(CXX) $(CXX_FLAGS) -MMD -S $(VERBOSE_ASM_FLAG) $< -o $@
@cp $(ASMOUTDIR)/$*.d $(DEPDIR)/$*.P
@rm -f $(ASMOUTDIR)/$*.d



-include $(PFILES)

#¯\(°_o)/¯


.PHONY : clean
clean :
rm -rfv $(OBJDIR) $(DEPDIR) $(ASMOUTDIR) $(PREPROCDIR) $(PROJ) tags *.taghl gmon.out


# Flags for make disassemble*
DISASSEMBLE_FLAGS:=$(DISASSEMBLE_BASE_FLAGS) -C -d
DISASSEMBLE_ALL_FLAGS:=$(DISASSEMBLE_BASE_FLAGS) -C -D

DISASSEMBLE_2_FLAGS:=$(DISASSEMBLE_BASE_FLAGS) -C -S -l -d
DISASSEMBLE_ALL_2_FLAGS:=$(DISASSEMBLE_BASE_FLAGS) -C -S -l -D

.PHONY : disassemble
disassemble :
$(OBJDUMP) $(DISASSEMBLE_FLAGS) $(PROJ)

.PHONY : disassemble_all
disassemble_all :
$(OBJDUMP) $(DISASSEMBLE_ALL_FLAGS) $(PROJ)


.PHONY : disassemble_2
disassemble_2 :
$(OBJDUMP) $(DISASSEMBLE_2_FLAGS) $(PROJ)

.PHONY : disassemble_all_2
disassemble_all_2 :
$(OBJDUMP) $(DISASSEMBLE_ALL_2_FLAGS) $(PROJ)
Binary file added example.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
115 changes: 115 additions & 0 deletions src/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
#include "misc_includes.hpp"
#include "wfc_class.hpp"

int main(int argc, char** argv) {
//--------
Vec2<size_t> size_2d;

if (argc < 4 || argc > 5) {
printerr("Usage 1: ", argv[0], " input_tiles_file width height\n");
printerr("Usage 2: ", argv[0],
" input_tiles_file width height rng_seed\n");
exit(1);
}
//ArgParser ap;
//ap.add("--ifile", "-i", HasArg::Req);
//ap.add("--width", "-w", HasArg::Req);
//ap.add("--height", "-h", HasArg::Req);
//ap.parse(argc, argv);

std::vector<std::vector<u32>> input_tiles;
if (
std::fstream file(argv[1], std::ios_base::in);
file.is_open()
) {
while (!file.eof()) {
std::string line;
std::getline(file, line);
if (file.eof() && line.size() == 0) {
} else if (
input_tiles.size() > 0
&& input_tiles.back().size() != line.size()
) {
printerr
("Input tiles file \"", argv[1], "\" has ",
"difference in line sizes ",
"(found first instance at line numbers ",
"[", input_tiles.size(), ", ",
(input_tiles.size() + size_t(1)), "])"
"\n");
exit(1);
} else if (line.size() == 0) {
printerr("Input tiles file \"", argv[1], "\" has line ",
"of size 0 ",
"(found first instance at line number ",
input_tiles.size(), ")",
"\n");
exit(1);
} else {
//input_tiles.push_back(std::move(line));
std::vector<u32> darr;
for (const auto& c: line) {
darr.push_back(static_cast<u32>(c));
}
input_tiles.push_back(std::move(darr));
}
}
} else {
printerr("Couldn't open input tiles file \"", argv[1], "\" for ",
"reading.\n");
exit(1);
}
//printout("Read in this these `input_tiles`\n");
//for (size_t j=0; j<input_tiles.size(); ++j) {
// printout(j, ": ", input_tiles.at(j), "\n");
//}

for (size_t i=0; i<size_2d.size(); ++i) {
inv_sconcat(std::string(argv[i + 2]), size_2d.at(i));

if (size_2d.at(i) < 1 || size_2d.at(i) > 32) {
if (i == size_2d.IND_X) {
printerr("`width` (", size_2d.at(i), ") must be in the ",
"range [1, 32]\n");
} else if (i == size_2d.IND_Y) {
printerr("`height` (", size_2d.at(i), ") must be in the ",
"range [1, 32]\n");
}
exit(1);
}
}

u64 seed;

if (argc == 4) {
seed = get_hrc_now_rng_seed();
} else { // if (argc == 5)
inv_sconcat(std::string(argv[4]), seed);
}

wfc::Wfc the_wfc(size_2d, seed, input_tiles);
for (size_t j=0; j<the_wfc.potential().size(); ++j) {
const auto& row = the_wfc.potential().at(j);
printout(j, ": ");
for (size_t i=0; i<row.size(); ++i) {
const auto& uset = row.at(i);
if (uset.size() != 1) {
printerr("main(): Eek! ",
"{", i, ", ", j, "}: ", uset.size(), "\n");
exit(1);
}
//printout(i32(uset.begin()->first));
//printout(uset.begin()->first);
printout(static_cast<char>(*uset.begin()));
//for (const auto& item: umap) {
// if (item.second) {
// printout(item.first);
// break;
// }
//}
}
printout("\n");
}

return 0;
}
2 changes: 1 addition & 1 deletion src/misc_includes.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
#include "liborangepower_src/concepts/is_specialization_concepts.hpp"
#include "liborangepower_src/math/vec2_classes.hpp"
#include "liborangepower_src/math/shape_2d_classes.hpp"
//#include "liborangepower_src/time/time_stuff.hpp"
#include "liborangepower_src/time/time_stuff.hpp"
//#include "liborangepower_src/arg_parser_class.hpp"

using namespace liborangepower::misc_output;
Expand Down
19 changes: 10 additions & 9 deletions src/rule_class.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,17 +36,18 @@ constexpr inline std::ostream& operator << (
switch (d) {
//--------
case Dir::Left:
return osprintout(os, "Dir::Left");
os << "Dir::Left";
case Dir::Top:
return osprintout(os, "Dir::Top");
os << "Dir::Top";
case Dir::Right:
return osprintout(os, "Dir::Right");
os << "Dir::Right";
case Dir::Bottom:
return osprintout(os, "Dir::Bottom");
os << "Dir::Bottom";
default:
return osprintout(os, "Dir::Bad");
os << "Dir::Bad";
//--------
}
return os;
}

class Rule final {
Expand All @@ -66,13 +67,13 @@ class Rule final {
}
};
using RuleUset = std::unordered_set<Rule>;
constexpr inline std::ostream& operator << (
inline std::ostream& operator << (
std::ostream& os, const Rule& rule
) {
os
<< "{" << "\'" << rule.t0 << "\' << "
<< "\'" << rule.t1 << "\' << "
<< rule.d << "}";
<< "{" << "\'" << rule.t0 << "\', "
<< "\'" << rule.t1 << "\', "
<< rule.d << "}";
return os;
}
//--------
Expand Down

0 comments on commit 331c4d0

Please sign in to comment.