Skip to content

Commit

Permalink
http and uri classes, mixer::set_hrtf, tts fixes etc
Browse files Browse the repository at this point in the history
* Finally registered a nice http class reminiscent of bgt's or the curl plugin! It's currently slightly documented.

* Register the spec::uri and http_credentials classes. Caused micro cleanup in pocostuff.cpp regarding value constructors.

* It is now possible to properly set an hrtf effect on an entire mixer using mixer.set_hrtf and mixer.set_position.

* Fix tts_voice.stop() on some platforms, as well as tts_voice.speak_to_file/speak_to_memory on windows.

* SConstruct modifications for debug libraries on windows, mostly internal for now.

* Very minor work on reactphysics, I think just registered one extra enum.

* Fix enet license after replacement with singleheader version.
  • Loading branch information
samtupy committed Nov 9, 2024
1 parent 6327dcd commit da4a633
Show file tree
Hide file tree
Showing 19 changed files with 524 additions and 108 deletions.
4 changes: 2 additions & 2 deletions SConstruct
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ if ARGUMENTS.get("debug", "0") == "1":
cdb = env.CompilationDatabase()
Alias('cdb', cdb)
if env["PLATFORM"] == "win32":
env.Append(CCFLAGS = ["/EHsc", "/J", "/MT", "/Z7", "/std:c++20", "/GF", "/Zc:inline", "/O2", "/bigobj", "/permissive-"])
env.Append(CCFLAGS = ["/EHsc", "/J", "/MT" if not "windev_debug" in env else "/MTd", "/Z7", "/std:c++20", "/GF", "/Zc:inline", "/O2", "/bigobj", "/permissive-"])
env.Append(LINKFLAGS = ["/NOEXP", "/NOIMPLIB"], no_import_lib = 1)
env.Append(LIBS = ["UniversalSpeechStatic", "angelscript64", "SDL3"])
env.Append(LIBS = ["Kernel32", "User32", "imm32", "OneCoreUAP", "dinput8", "dxguid", "gdi32", "winspool", "shell32", "iphlpapi", "ole32", "oleaut32", "delayimp", "uuid", "comdlg32", "advapi32", "netapi32", "winmm", "version", "crypt32", "normaliz", "wldap32", "ws2_32"])
Expand Down Expand Up @@ -73,7 +73,7 @@ if "version.cpp" in sources: sources.remove("version.cpp")
env.Command(target = "src/version.cpp", source = ["src/" + i for i in sources], action = env["generate_version"])
version_object = env.Object("build/obj_src/version", "src/version.cpp") # Things get weird if we do this after VariantDir.
VariantDir("build/obj_src", "src", duplicate = 0)
env.Append(LIBS = [["PocoFoundationMT", "PocoJSONMT", "PocoNetMT", "PocoNetSSLWinMT", "PocoUtilMT", "PocoZipMT"] if env["PLATFORM"] == "win32" else ["PocoJSON", "PocoNet", "PocoNetSSL", "PocoUtil", "PocoCrypto", "PocoZip", "PocoFoundation"], "phonon", "bass", "bass_fx", "bassmix", "reactphysics3d"])
env.Append(LIBS = [["PocoJSON", "PocoNet", "PocoNetSSL", "PocoUtil", "PocoCrypto", "PocoZip", "PocoFoundation"] if env["PLATFORM"] != "win32" else [], "phonon", "bass", "bass_fx", "bassmix", "reactphysics3d"])
env.Append(CPPDEFINES = ["NVGT_BUILDING", "NO_OBFUSCATE"], LIBS = ["ASAddon", "deps"])
if env["PLATFORM"] == "win32":
env.Append(LINKFLAGS = ["/OPT:REF", "/OPT:ICF", "/ignore:4099", "/delayload:bass.dll", "/delayload:bass_fx.dll", "/delayload:bassmix.dll", "/delayload:phonon.dll"])
Expand Down
1 change: 1 addition & 0 deletions build/osdev_sconscript.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ def set_osdev_paths(env, osdev_path = prefix + "dev"):
if env["PLATFORM"] == "win32":
env.Append(LIBPATH = [os.path.join(osdev_path, "bin")])
env["NVGT_OSDEV_PATH"] = osdev_path
if "debug" in osdev_path: env["windev_debug"] = 1

set_osdev_paths(env)

Expand Down
4 changes: 3 additions & 1 deletion doc/OSL/MIT/enet.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
enet library

Copyright (c) 2002-2024 Lee Salzman
Copyright (c) 2002-2016 Lee Salzman

Copyright (c) 2017-2022 Vladyslav Hrytsenko, Dominik Madar�sz

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/**
Initiate a get request.
bool get(spec::uri url, name_value_collection@ headers = null, http_credentials@ creds = null);
## Arguments:
* spec::uri url: A valid URI which must have a scheme of either http or https.
* name_value_collection@ headers = null: Pairs of extra http headers to pass on to the server.
* http_credentials@ creds = null: Optional credentials to authenticate the request with.
## Returns:
bool: True if the request was initiated, or false if there was an error.
## Remarks:
Once this method is called and returns true, you will usually want to wait until either http.complete returns true or http.running returns false before thoroughly handling the request. However http.progress, http.status_code, http.response_headers and http.response_body are accessible throughout the request's lifecycle to stream the data or get more detailed information.
*/

// Example:
void main() {
// Fetch the latest version of NVGT.
http h;
if (!h.get("http://nvgt.gg/downloads/latest_version")) {
alert("oops", "request failed"); // This class will contain more detailed error management facilities in the near future.
return;
}
h.wait(); // You can also use the h.running or h.complete properties in a loop to execute code in the background while the request progresses.
alert("nvgt latest version", h.response_body);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/**
Resets the http object to the state it was in at the time of it's construction, canceling any requests in progress.
void reset();
## Remarks:
This method waits for the current request to cancel successfully, which is usually instant. However from time to time you could see a small delay as the request thread runs to the next point where it can check the cancelation event.
This method is implicitly called whenever the http object destructs.
*/

// Example:
void main() {
http h;
h.get("https://nvgt.gg");
wait(20);
h.reset();
h.get("https://samtupy.com/ip.php");
h.wait();
if (h.status_code != 200) alert("oops " + h.status_code, h.response_body);
else alert("IP address displayed after http reset", h.response_body);
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# wait
Waits for the current request to complete.

`void wait();`

## Remarks:
If no request is in progress, this will return emmedietly. Otherwise, it will block code execution on the calling thread until the request has finished.
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# progress
Determine the percentage of the request download (from 0.0 to 1.0.

`const float progress;`

## Remarks:
This property will be 0 if a request is not in progress or if it is not yet in a state where the content length of the download can be known, and -1 if the progress cannot be determined such as if the remote endpoint does not provide a Content-Length header.
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# response_body
Read and consume any new data from the current request.

`const string response_body;`

## Remarks:
It is important to note that accessing this property will flush the buffer stored in the request. This means that for example you do not want to access http.response_body.length(); because the next time http.response_body is accessed it will be empty or might contain new data.

Proper usage is to continuously append the value of this property to a string or datastream in a loop while h.running is true or h.complete is false.
37 changes: 37 additions & 0 deletions doc/src/references/builtin/Networking/classes/http/http.nvgt
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/**
Facilitate HTTP requests from a simple, asynchronous interface.
http();
## Remarks:
This is one of the easiest ways to perform an http request in NVGT without blocking the rest of your code.
Simply create an http object, call either it's get, head or post methods, then begin accessing properties on the object such as progress, status_code or response_body to query and access details of the request.
*/

// Example:
#include "size.nvgt"
#include "speech.nvgt"
void main() {
// This script downloads the latest NVGT windows installer and saves it in the current working directory.
http h;
h.get("https://nvgt.zip/windows");
file f;
string filename = "";
show_window("downloading...");
while (!h.complete) {
wait(5);
if (key_pressed(KEY_ESCAPE)) {
f.close();
file_delete(filename);
return; // Destruction of the http object will cancel any requests in progress.
}
if (!f.active and h.status_code == 200) { // The file is available.
string[]@ path = h.url.get_path_segments();
filename = path.length() > 0? path[-1] : "http.txt";
f.open(filename, "wb");
}
if (f.active) f.write(h.response_body);
if (key_pressed(KEY_SPACE)) speak(round(h.progress * 100, 2) + "%");
}
int keep = question(filename, size_to_string(f.size) + " downloaded, keep file?");
f.close();
if (keep != 1) file_delete(filename);
}
Loading

0 comments on commit da4a633

Please sign in to comment.