Skip to content

Commit

Permalink
Merge pull request #30 from jaihysc/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
jaihysc authored Apr 26, 2021
2 parents 4056b4c + 27989ab commit cf6d261
Show file tree
Hide file tree
Showing 85 changed files with 1,855 additions and 1,858 deletions.
14 changes: 14 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,20 @@ function(jactorio_copy_runtime_files)

endfunction()

# Add preprocesor definition of FILENAME to pass the filename without directory path
# For each source file depended on by TARGET_NAME, where FILENAME is the name of the file.
function(define_filename_for_sources TARGET_NAME)
get_target_property(SOURCE_FILES "${TARGET_NAME}" SOURCES)

foreach(SOURCE_FILE ${SOURCE_FILES})
get_filename_component(FILE_BASE_NAME "${SOURCE_FILE}" NAME)

# Set the updated compile definitions on the source file.
set_property(SOURCE "${SOURCE_FILE}" APPEND
PROPERTY COMPILE_DEFINITIONS "FILENAME=\"${FILE_BASE_NAME}\""
)
endforeach()
endfunction()



Expand Down
26 changes: 7 additions & 19 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,29 +8,17 @@ My attempt at recreating [Factorio](https://factorio.com), inspired by [Hopson98

[Weekly log](https://github.com/jaihysc/Jactorio/wiki/Devlog)

## Work in progress

- [x] World Generation
- [x] Transport lines
- [x] Drills
- [x] Inserters
- [x] Assembly Machines
- [ ] Splitters
- [ ] Underground belts
- [ ] Smelting / Furnaces

## Building

Requirements:

* Compiler supporting c++17 [gcc >= 9, clang >= 9, msvc >= 142]
* Compiler supporting c++17 [Tested on: gcc >= 9, clang >= 9, msvc >= 142]
* Python interpreter 3.x.x
* CMake

Remarks:

* Windows - Ensure CMake is added to the `Paths` environmental variable
* Windows - Use git bash to run the bash files
* MacOS - Version >= 10.15

---
Expand All @@ -39,21 +27,21 @@ Remarks:

**Parameters:** `--notest` if you do not want to build the tests

Executable will be placed in `out/<Build type>/src/`
Executable will be placed in `out/<Build type>/bin/`

---

In a bash shell on Windows, Mac and Linux:
In a shell:

```bash
git clone https://github.com/jaihysc/Jactorio.git
cd Jactorio
sh ./build.sh <See build types above> --notest
./build.sh <See build types above> --notest
```

## Running tests

**Test parameters:** `--leakcheck` to perform a leak check, skipping some false positive tests
**Test parameters:** `--leakcheck` to perform a leak check using valgrind, skipping some false positive tests

The test results will be placed in the directory of `runtests.sh`

Expand All @@ -62,12 +50,12 @@ The test results will be placed in the directory of `runtests.sh`
After following the build steps above **without** `--notest`

```bash
sh ./runtests.sh <Build type used to build>
./runtests.sh <Build type used to build>
```

## Dependencies

The installation of dependencies listed below is automatic
The installation of dependencies listed below is automatic, but may carry additional dependencies **you** must install:

* [backward-cpp](https://github.com/bombela/backward-cpp)
* [cereal](https://github.com/USCiLab/cereal)
Expand Down
1 change: 0 additions & 1 deletion data/base/prototypes/entity/assemblyMachines.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ def addAssemblyMachine(name, iconSpritePath, worldSpritePath):
.tileWidth(3)
.tileHeight(3)

.pickupTime(0.1)
.assemblySpeed(1)
.rotatable(True)
)
Expand Down
1 change: 0 additions & 1 deletion data/base/prototypes/entity/belts.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ def addBelt(name, iconSpritePath, worldSpritePath):
.sets(20)
.trim(16)
)
.pickupTime(0.1)
.speed(0.05)
.rotatable(True)
)
Expand Down
2 changes: 0 additions & 2 deletions data/base/prototypes/entity/containers.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ def addContainer(name, invSize, health, worldSprite, itemSprite):
.maxHealth(health)
.inventorySize(invSize)

.pickupTime(0.1)

.sprite(
j.Sprite()
.load(worldSprite)
Expand Down
1 change: 0 additions & 1 deletion data/base/prototypes/entity/inserters.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ def addInserter(name, itemSprite,
worldSprite, handSprite, armSprite,
rotationSpeed, tileReach):
(j.Inserter(name)
.pickupTime(0.1)
.rotationSpeed(rotationSpeed)

.rotatable(True)
Expand Down
1 change: 0 additions & 1 deletion data/base/prototypes/entity/miningDrills.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ def addSprite(spritePath):
def createDrill(name, icon, spriteN, spriteE, spriteS, spriteW):
(j.MiningDrill(name)
.rotatable(True)
.pickupTime(0.1)
.miningSpeed(1)

.item(
Expand Down
1 change: 0 additions & 1 deletion data/base/prototypes/entity/splitters.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ def addSprite(spritePath):
def createSplitter(name, icon, spriteN, spriteE, spriteS, spriteW):
(j.Splitter(name)
.rotatable(True)
.pickupTime(0.1)

.item(j.Item(name + "-item")
.sprite(
Expand Down
15 changes: 2 additions & 13 deletions data/core/data.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import core.prototypes.local

import jactorioData as j

def addSprite(name, spritePath):
Expand Down Expand Up @@ -37,16 +39,3 @@ def addItem(name, path):

addItem("inventory-selected-cursor", "core/graphics/hand.png")
addItem("reset", "core/graphics/reset.png")


# Labels
for i in range(13):
j.Label("label:player-action-" + str(i))

j.Label("label:key-action-none")
j.Label("label:key-action-key-down")
j.Label("label:key-action-key-pressed")
j.Label("label:key-action-key-repeat")
j.Label("label:key-action-key-held")
j.Label("label:key-action-key-up")

Binary file added data/core/font/NotoSans-Regular.ttf
Binary file not shown.
27 changes: 27 additions & 0 deletions data/core/local/en.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,30 @@ label:key-action-key-pressed=Key pressed (down + before repeat)
label:key-action-key-repeat=Key repeat
label:key-action-key-held=Key held (pressed + repeat)
label:key-action-key-up=Key up

label:key-mouse-left=Mouse left
label:key-mouse-middle=Mouse middle
label:key-mouse-right=Mouse right
label:key-mouse-x1=Mouse X1
label:key-mouse-x2=Mouse X2

label:menu-main=Main menu
label:menu-new-game=New game
label:menu-new-game-seed=Seed
label:menu-new-game-play=Play
label:menu-load-game=Load game
label:menu-load-game-play=Play
label:menu-save-game=Save game
label:menu-save-game-invalid-name=Invalid save name
label:menu-save-game-save-name=Save name
label:menu-save-game-save=Save
label:menu-options=Options
label:menu-option-change-keybind=Keybind
label:menu-option-change-keybind-key=Key
label:menu-option-change-keybind-name=Name
label:menu-option-change-keybind-action=Action
label:menu-option-change-keybind-reset=Reset
label:menu-option-toggle-fullscreen=Toggle fullscreen
label:menu-option-change-language=Language
label:menu-option-change-language-restart-notice=Restart to apply language changes
label:menu-quit=Quit
46 changes: 46 additions & 0 deletions data/core/prototypes/local.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import jactorioData as j

(j.Localization()
.identifier("en")
.fontPath("core/font/NotoSans-Regular.ttf")
.fontSize(16)
)

# Labels

for i in range(13):
j.Label("label:player-action-" + str(i))

j.Label("label:key-action-none")
j.Label("label:key-action-key-down")
j.Label("label:key-action-key-pressed")
j.Label("label:key-action-key-repeat")
j.Label("label:key-action-key-held")
j.Label("label:key-action-key-up")

j.Label("label:key-mouse-left")
j.Label("label:key-mouse-middle")
j.Label("label:key-mouse-right")
j.Label("label:key-mouse-x1")
j.Label("label:key-mouse-x2")

j.Label("label:menu-main")
j.Label("label:menu-new-game")
j.Label("label:menu-new-game-seed")
j.Label("label:menu-new-game-play")
j.Label("label:menu-load-game")
j.Label("label:menu-load-game-play")
j.Label("label:menu-save-game")
j.Label("label:menu-save-game-invalid-name")
j.Label("label:menu-save-game-save-name")
j.Label("label:menu-save-game-save")
j.Label("label:menu-options")
j.Label("label:menu-option-change-keybind")
j.Label("label:menu-option-change-keybind-key")
j.Label("label:menu-option-change-keybind-name")
j.Label("label:menu-option-change-keybind-action")
j.Label("label:menu-option-change-keybind-reset")
j.Label("label:menu-option-toggle-fullscreen")
j.Label("label:menu-option-change-language")
j.Label("label:menu-option-change-language-restart-notice")
j.Label("label:menu-quit")
6 changes: 6 additions & 0 deletions data/test/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,9 @@ def addProto(name, sprite_path):
addProto("test_tile1", "test/graphics/test/test_tile1.png")
addProto("test_tile2", "test/graphics/test/test_tile2.png")
addProto("test_tile3", "test/graphics/test/test_tile3.png")

(j.Localization()
.identifier("test-blank-local")
.fontPath("core/font/NotoSans-Regular.ttf")
.fontSize(16)
)
1 change: 1 addition & 0 deletions data/test/local/test.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
test_tile=Localized Test Tile
58 changes: 54 additions & 4 deletions include/core/convert.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,15 @@
#pragma once

#include <type_traits>
#include <typeinfo>

#include "jactorio.h"

namespace jactorio
{
/// Performs cast, data may be lost
template <class TTarget, class TOriginal>
constexpr TTarget LossyCast(
template <typename TTarget, typename TOriginal>
J_NODISCARD constexpr TTarget LossyCast(
TOriginal val,
std::enable_if_t<std::is_integral_v<TOriginal> || std::is_floating_point_v<TOriginal>, int> = 0,
std::enable_if_t<std::is_integral_v<TTarget> || std::is_floating_point_v<TTarget>, int> = 0) noexcept {
Expand All @@ -22,8 +23,8 @@ namespace jactorio

/// Performs cast ensuring no data is lost
/// \remark Same behavior as static cast if assertions are disabled
template <class TTargetInt, class TOriginalInt>
constexpr TTargetInt SafeCast(
template <typename TTargetInt, typename TOriginalInt>
J_NODISCARD constexpr TTargetInt SafeCast(
TOriginalInt val,
std::enable_if_t<std::is_integral_v<TOriginalInt>, int> = 0,
std::enable_if_t<std::is_integral_v<TTargetInt> || std::is_floating_point_v<TTargetInt>, int> = 0) noexcept {
Expand All @@ -46,6 +47,55 @@ namespace jactorio
l_val = SafeCast<std::remove_reference_t<decltype(l_val)>>(r_val);
}

/// Performs downcast of pointer safely
/// \remark Same behavior as static cast if non debug
template <typename TTarget, typename TOriginal>
J_NODISCARD constexpr auto* SafeCast(
TOriginal* ptr,
std::enable_if_t<std::is_pointer_v<TTarget> && //
std::is_base_of_v<TOriginal, std::remove_pointer_t<TTarget>> && //
std::is_polymorphic_v<TOriginal>,
int> = 0) noexcept {

#ifdef JACTORIO_DEBUG_BUILD
auto* cast_ptr = dynamic_cast<TTarget>(ptr);

if (ptr != nullptr) {
assert(cast_ptr != nullptr);
}
return cast_ptr;
#else
return static_cast<TTarget>(ptr);
#endif
}

/// Performs downcast of reference safely
/// \remark Same behavior as static cast if non debug
template <typename TTarget, typename TOriginal>
J_NODISCARD
#ifndef JACTORIO_DEBUG_BUILD
constexpr
#endif
auto& SafeCast(
TOriginal& ref,
std::enable_if_t<std::is_reference_v<TTarget> && //
std::is_base_of_v<TOriginal, std::remove_reference_t<TTarget>> && //
std::is_polymorphic_v<TOriginal>,
int> = 0) noexcept {

#ifdef JACTORIO_DEBUG_BUILD
try {
auto& cast_ref = dynamic_cast<TTarget>(ref);
return cast_ref;
}
catch (std::bad_cast&) {
assert(false);
return static_cast<TTarget>(ref); // Return something to make the compiler happy
}
#else
return static_cast<TTarget>(ref);
#endif
}
} // namespace jactorio

#endif // JACTORIO_INCLUDE_CORE_CONVERT_H
28 changes: 7 additions & 21 deletions include/core/logger.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,26 +4,12 @@
#define JACTORIO_INCLUDE_CORE_LOGGER_H
#pragma once

#include <string>
#include <cstdint>
#include <cstdio>
#include <type_traits>

// Damn Windows has to use backslashes for paths
// Cuts away paths, keeps only the filename
#ifdef _MSC_VER
#define FILENAME (strrchr(__FILE__, '\\') ? strrchr(__FILE__, '\\') + 1 : __FILE__)
#endif

#ifdef __GNUC__
#include <cstring>
#define FILENAME (strrchr(__FILE__, '/') ? strrchr(__FILE__, '/') + 1 : __FILE__)
#undef _MSC_VER
#endif

// Logging macros
//
// Prefer calling LOG_MESSAGE to log a message over log_message()
#define LOG_MESSAGE(severity__, format__) \
jactorio::MakeLogMessage<jactorio::LogSeverity::severity__>(format__, FILENAME, __LINE__)
#define LOG_MESSAGE(severity__, msg__) \
jactorio::MakeLogMessage<jactorio::LogSeverity::severity__>("%s", FILENAME, __LINE__, msg__)

// Allows the message to contain a format, similar to printf
#define LOG_MESSAGE_F(severity__, format__, ...) \
Expand Down Expand Up @@ -53,15 +39,15 @@ namespace jactorio

/// Logs a message to console
/// Format: Timestamp [severity] - [group] message
void LogMessage(LogSeverity severity, const std::string& group, int line, const std::string& message);
void LogMessage(LogSeverity severity, const char* group, int line, const char* message);

/// Converts log_severity to a string
/// \return The log severity as string
std::string LogSeverityStr(LogSeverity severity);
const char* LogSeverityStr(LogSeverity severity);

/// Converts log_severity to a string with color
/// \return The log severity as string
std::string LogSeverityStrColored(LogSeverity severity);
const char* LogSeverityStrColored(LogSeverity severity);


/// Creates a formatted log message if log level permits
Expand Down
Loading

0 comments on commit cf6d261

Please sign in to comment.