forked from ddnet/ddnet
-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9d29b96
commit d29a641
Showing
21 changed files
with
406 additions
and
85 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
message(STATUS "~~~~~~ chillerbot rust module ~~~~~~") | ||
|
||
set_glob(RUST_CHILLERBOT_RS GLOB_RECURSE "rs;toml;h;cpp" src/chillerbot-rs | ||
Cargo.toml | ||
build.rs | ||
lib.rs | ||
unicode.rs | ||
) | ||
|
||
set_src(RUST_BRIDGE_CHILLERBOT GLOB_RECURSE src/rust-bridge-chillerbot | ||
unicode.cpp | ||
unicode.h | ||
) | ||
|
||
add_library(rust-bridge-chillerbot EXCLUDE_FROM_ALL OBJECT ${RUST_BRIDGE_CHILLERBOT}) | ||
list(APPEND TARGETS_OWN rust-bridge-chillerbot) | ||
|
||
##################################################################### | ||
# overwrite variables if current content matches expected | ||
# | ||
# could probably also use list(APPEND ..) but lets me strict for now | ||
# to be alerted if somehing changes before weird build errors occur | ||
|
||
if(RUST_TARGETS STREQUAL "engine_shared") | ||
message(STATUS " * patching RUST_TARGETS ...") | ||
set(RUST_TARGETS engine_shared chillerbot_rs) | ||
else() | ||
message(SEND_ERROR " failed to patch RUST_TARGETS unexpected content '${RUST_TARGETS}'") | ||
endif() | ||
|
||
set(CHILLERBOT_EXPECTED_RUST_SRC | ||
${RUST_BASE} | ||
${RUST_ENGINE_INTERFACE} | ||
${RUST_ENGINE_SHARED} | ||
Cargo.toml | ||
Cargo.lock | ||
) | ||
|
||
if(RUST_SRC STREQUAL CHILLERBOT_EXPECTED_RUST_SRC) | ||
message(STATUS " * patching RUST_SRC ...") | ||
set(RUST_SRC | ||
${RUST_BASE} | ||
${RUST_ENGINE_INTERFACE} | ||
${RUST_ENGINE_SHARED} | ||
${RUST_CHILLERBOT_RS} | ||
Cargo.toml | ||
Cargo.lock | ||
) | ||
else() | ||
message(SEND_ERROR " failed to patch RUST_SRC unexpected content '${RUST_SRC}'") | ||
endif() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
foreach(target ${TARGETS_OWN}) | ||
if((CMAKE_VERSION VERSION_GREATER 3.1 OR CMAKE_VERSION VERSION_EQUAL 3.1)) | ||
set_property(TARGET ${target} PROPERTY CXX_STANDARD 17) | ||
set_property(TARGET ${target} PROPERTY CXX_STANDARD_REQUIRED ON) | ||
set_property(TARGET ${target} PROPERTY CXX_EXTENSIONS OFF) | ||
endif() | ||
target_include_directories(${target} PRIVATE src/rust-bridge-chillerbot) | ||
if(CURSES_CLIENT) | ||
target_compile_definitions(${target} PRIVATE CONF_CURSES_CLIENT) | ||
endif() | ||
endforeach() |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
[package] | ||
name = "ddnet-chillerbot-rs" | ||
version = "0.0.1" | ||
edition = "2018" | ||
publish = false | ||
license = "Zlib" | ||
|
||
[lib] | ||
crate-type = ["rlib", "staticlib"] | ||
path = "lib.rs" | ||
|
||
[dependencies] | ||
ddnet-base = { path = "../base" } | ||
ddnet-engine = { path = "../engine" } | ||
|
||
cxx = "1.0" | ||
unicode-width = "0.1.10" | ||
|
||
[dev-dependencies] | ||
ddnet-test = { path = "../rust-bridge/test", features = ["link-test-libraries"] } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
use std::env; | ||
use std::fs; | ||
use std::path::PathBuf; | ||
use std::process::Command; | ||
|
||
fn main() { | ||
let mut out = PathBuf::from(env::var_os("OUT_DIR").expect("OUT_DIR")); | ||
out.push("rustc-version"); | ||
let rustc = env::var_os("RUSTC").expect("RUSTC"); | ||
let rustc_output = Command::new(rustc) | ||
.arg("--version") | ||
.output() | ||
.expect("rustc --version"); | ||
if !rustc_output.status.success() { | ||
panic!("rustc --version: exit status {}", rustc_output.status); | ||
} | ||
fs::write(&out, rustc_output.stdout).expect("file write"); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
//! chillerbots's engine interfaces, Rust part. | ||
//! | ||
//! DDNet's code base is separated into three major parts, `base`, `engine` and | ||
//! `game`. | ||
//! | ||
//! The engine consists of game-independent code such as display setup, | ||
//! low-level network protocol, low-level map format, etc. | ||
//! | ||
//! This crate in particular corresponds to the `src/engine/shared` directory | ||
//! that contains code shared between client, server and other components. | ||
#![warn(missing_docs)] | ||
|
||
#[cfg(test)] | ||
extern crate ddnet_test; | ||
|
||
mod unicode; | ||
|
||
pub use unicode::*; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
use std::ffi::CStr; | ||
use std::os::raw::c_char; | ||
|
||
extern crate unicode_width; | ||
|
||
use unicode_width::UnicodeWidthStr; | ||
|
||
#[cxx::bridge] | ||
mod ffi { | ||
extern "C++" { | ||
include!("base/rust.h"); | ||
} | ||
extern "Rust" { | ||
unsafe fn str_width_unicode(text: *const c_char) -> i32; | ||
} | ||
} | ||
|
||
/// Count the width in columns of a given string. | ||
/// | ||
/// So one can get the display length of any string | ||
/// in a fixed width font scenario. | ||
/// | ||
/// Simply calling str_length() does not work if there is unicode | ||
/// since some unicode characters can be multiple bytes | ||
/// and even counting unicode characters does not work | ||
/// because CJK (chines/japan/korean) characters | ||
/// have a concept of full and half width | ||
/// meaning one single unicode character can span two columns | ||
/// | ||
/// For example this character spans two columns | ||
/// ```text | ||
/// +--+ | ||
/// |困| | ||
/// |12| | ||
/// +--+ | ||
/// ``` | ||
#[allow(non_snake_case)] | ||
pub fn str_width_unicode(text: *const c_char) -> i32 { | ||
let slice = unsafe { CStr::from_ptr(text) }; | ||
let slice = slice.to_str().unwrap_or_default(); | ||
// .width_cjk().try_into().unwrap(); | ||
// returns width 2 for the letter é | ||
let width = UnicodeWidthStr::width(slice) as i32; | ||
return width; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletions
23
src/game/client/components/chillerbot/terminalui/pad_utf8.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
#if defined(CONF_CURSES_CLIENT) | ||
|
||
#include "pad_utf8.h" | ||
#include <base/system.h> | ||
|
||
#include <rust-bridge-chillerbot/unicode.h> | ||
|
||
void str_pad_right_utf8(char *pStr, int size, int pad_len) | ||
{ | ||
char aBuf[2048]; | ||
str_copy(aBuf, pStr, sizeof(aBuf)); | ||
int full_width_length = str_width_unicode(pStr); | ||
int c_len = str_length(pStr); | ||
int pad_len_utf8_rust = pad_len - (full_width_length - c_len); | ||
|
||
str_format(pStr, size, "%-*s", pad_len_utf8_rust, aBuf); | ||
// dbg_msg( | ||
// "pad", | ||
// "pad_len=%d pad_len_utf8_rust=%d res='%s'", | ||
// pad_len, pad_len_utf8_rust, pStr); | ||
} | ||
|
||
#endif |
Oops, something went wrong.