mirror of
https://github.com/ondra-novak/gates_of_skeldal.git
synced 2025-07-07 15:10:32 -04:00
trying to debug, additional rewrites
This commit is contained in:
parent
378b5586ab
commit
42f780a729
87 changed files with 1771 additions and 529 deletions
2
platform/linux/CMakeLists.txt
Normal file
2
platform/linux/CMakeLists.txt
Normal file
|
@ -0,0 +1,2 @@
|
|||
|
||||
add_library(skeldal_linux map_file.cpp timer.cpp)
|
59
platform/linux/map_file.cpp
Normal file
59
platform/linux/map_file.cpp
Normal file
|
@ -0,0 +1,59 @@
|
|||
|
||||
extern "C" {
|
||||
#include "map_file.h"
|
||||
}
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <fcntl.h>
|
||||
#include <sys/mman.h>
|
||||
#include <sys/stat.h>
|
||||
#include <unistd.h>
|
||||
|
||||
// Funkce pro mapování souboru do paměti
|
||||
void* map_file_to_memory(const char *name, size_t *sz) {
|
||||
if (!name || !sz) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
// Otevření souboru pro čtení
|
||||
int fd = open(name, O_RDONLY);
|
||||
if (fd == -1) {
|
||||
perror("Chyba při otevírání souboru");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
// Získání velikosti souboru
|
||||
struct stat st;
|
||||
if (fstat(fd, &st) == -1) {
|
||||
perror("Chyba při získávání velikosti souboru");
|
||||
close(fd);
|
||||
return NULL;
|
||||
}
|
||||
*sz = st.st_size;
|
||||
|
||||
// Namapování souboru do paměti
|
||||
void *mapped = mmap(NULL, *sz, PROT_READ, MAP_PRIVATE, fd, 0);
|
||||
if (mapped == MAP_FAILED) {
|
||||
perror("Chyba při mapování souboru");
|
||||
close(fd);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
// Zavření souborového popisovače (není již potřeba po mmap)
|
||||
close(fd);
|
||||
|
||||
return mapped;
|
||||
}
|
||||
|
||||
// Funkce pro zrušení mapování
|
||||
void unmap_file(void *ptr, size_t sz) {
|
||||
if (!ptr || sz == 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Zrušení mapování
|
||||
if (munmap(ptr, sz) == -1) {
|
||||
perror("Chyba při rušení mapování");
|
||||
}
|
||||
}
|
4
platform/linux/map_file.h
Normal file
4
platform/linux/map_file.h
Normal file
|
@ -0,0 +1,4 @@
|
|||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
void *map_file_to_memory(const char *name, size_t *sz);
|
||||
void unmap_file(void *ptr, size_t sz);
|
18
platform/linux/timer.cpp
Normal file
18
platform/linux/timer.cpp
Normal file
|
@ -0,0 +1,18 @@
|
|||
#include "timer.h"
|
||||
#include <chrono>
|
||||
#include "../platform.h"
|
||||
|
||||
#include <thread>
|
||||
int get_timer_value() {
|
||||
auto n = std::chrono::steady_clock::now();
|
||||
return std::chrono::duration_cast<std::chrono::milliseconds>(n.time_since_epoch()).count()/TIMERSPEED;
|
||||
}
|
||||
|
||||
uint32_t get_game_tick_count() {
|
||||
auto n = std::chrono::steady_clock::now();
|
||||
return std::chrono::duration_cast<std::chrono::milliseconds>(n.time_since_epoch()).count();
|
||||
}
|
||||
|
||||
void sleep_ms(uint32_t x) {
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(x));
|
||||
}
|
28
platform/linux/timer.h
Normal file
28
platform/linux/timer.h
Normal file
|
@ -0,0 +1,28 @@
|
|||
/*
|
||||
* timer.h
|
||||
*
|
||||
* Created on: 26. 1. 2025
|
||||
* Author: ondra
|
||||
*/
|
||||
|
||||
#ifndef PLATFORM_LINUX_TIMER_H_
|
||||
#define PLATFORM_LINUX_TIMER_H_
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
int get_timer_value();
|
||||
uint32_t get_game_tick_count();
|
||||
void sleep_ms(uint32_t);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
|
||||
#endif /* PLATFORM_LINUX_TIMER_H_ */
|
Loading…
Add table
Add a link
Reference in a new issue