initial commit
This commit is contained in:
commit
a0223f8e4e
2
.gitignore
vendored
Normal file
2
.gitignore
vendored
Normal file
@ -0,0 +1,2 @@
|
||||
.idea
|
||||
cmake-build-debug
|
||||
20
CMakeLists.txt
Normal file
20
CMakeLists.txt
Normal file
@ -0,0 +1,20 @@
|
||||
cmake_minimum_required(VERSION 4.1)
|
||||
project(tibia C)
|
||||
|
||||
set(CMAKE_C_STANDARD 11)
|
||||
|
||||
find_package(SDL3 CONFIG REQUIRED)
|
||||
|
||||
add_executable(tibia main.c
|
||||
app.c
|
||||
window.c
|
||||
system.c
|
||||
system.h
|
||||
render.c
|
||||
render.h
|
||||
input.c
|
||||
input.h
|
||||
config.c
|
||||
config.h)
|
||||
|
||||
target_link_libraries(tibia SDL3::SDL3)
|
||||
26
app.c
Normal file
26
app.c
Normal file
@ -0,0 +1,26 @@
|
||||
#include "app.h"
|
||||
#include "window.h"
|
||||
#include "render.h"
|
||||
#include "input.h"
|
||||
|
||||
void App_Init(App_t *app) {
|
||||
Window_Init_SDL();
|
||||
System_QueryMetrics(&app->metrics);
|
||||
|
||||
Window_Init(app->metrics.screenWidth, app->metrics.screenHeight);
|
||||
|
||||
Config_Load_Settings(&app->configParams);
|
||||
|
||||
app->isRunning = true;
|
||||
}
|
||||
|
||||
void App_Run(App_t *app) {
|
||||
while (app->isRunning) {
|
||||
Input_Poll(app);
|
||||
Render_Frame();
|
||||
}
|
||||
}
|
||||
|
||||
void App_Shutdown(App_t *app) {
|
||||
Window_Shutdown();
|
||||
}
|
||||
19
app.h
Normal file
19
app.h
Normal file
@ -0,0 +1,19 @@
|
||||
#ifndef APP_H
|
||||
#define APP_H
|
||||
|
||||
#include <stdbool.h>
|
||||
|
||||
#include "config.h"
|
||||
#include "system.h"
|
||||
|
||||
typedef struct App {
|
||||
bool isRunning;
|
||||
SystemMetrics_t metrics;
|
||||
ConfigParams_t configParams;
|
||||
} App_t;
|
||||
|
||||
void App_Init(App_t* app);
|
||||
void App_Run(App_t* app);
|
||||
void App_Shutdown(App_t* app);
|
||||
|
||||
#endif
|
||||
47
config.c
Normal file
47
config.c
Normal file
@ -0,0 +1,47 @@
|
||||
//
|
||||
// Created by rov on 12/26/25.
|
||||
//
|
||||
|
||||
#include "config.h"
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <SDL3/SDL_log.h>
|
||||
|
||||
void Config_Load_Settings(ConfigParams_t* configParams) {
|
||||
FILE* configFile = fopen("CLIENT.CFG", "rb");
|
||||
|
||||
if (configFile != NULL) {
|
||||
SDL_LogInfo(SDL_LOG_CATEGORY_CUSTOM, "Config_Load_Settings: loaded CLIENT.CFG");
|
||||
|
||||
fread(configParams->serverAddress, 1, 100, configFile);
|
||||
fread(&configParams->serverPort, 1, 4, configFile);
|
||||
fread(configParams->lastAccount, 1, 30, configFile);
|
||||
fread(configParams->lastPassword, 1, 30, configFile);
|
||||
|
||||
fclose(configFile);
|
||||
return;
|
||||
}
|
||||
|
||||
SDL_LogInfo(SDL_LOG_CATEGORY_CUSTOM, "Config_Load_Settings: couldn't load CLIENT.CFG. Using default values.");
|
||||
|
||||
strcpy(configParams->serverAddress, "rrws27.uni-regensburg.de");
|
||||
configParams->serverPort = 7171;
|
||||
configParams->lastAccount[0] = '\0';
|
||||
configParams->lastPassword[0] = '\0';
|
||||
}
|
||||
|
||||
void Config_Save_Settings(ConfigParams_t* configParams) {
|
||||
FILE* configFile = fopen("CLIENT.CFG", "wb");
|
||||
|
||||
if (configFile == NULL) {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_CUSTOM, "Config_Save_Settings: couldn't open config file.");
|
||||
return;
|
||||
}
|
||||
|
||||
fwrite(configParams->serverAddress, 1, 100, configFile);
|
||||
fwrite(&configParams->serverPort, 1, 4, configFile);
|
||||
fwrite(configParams->lastAccount, 1, 30, configFile);
|
||||
fwrite(configParams->lastPassword, 1, 30, configFile);
|
||||
|
||||
fclose(configFile);
|
||||
}
|
||||
18
config.h
Normal file
18
config.h
Normal file
@ -0,0 +1,18 @@
|
||||
//
|
||||
// Created by rov on 12/26/25.
|
||||
//
|
||||
|
||||
#ifndef TIBIA_CONFIG_H
|
||||
#define TIBIA_CONFIG_H
|
||||
|
||||
typedef struct ConfigParams {
|
||||
char serverAddress[100];
|
||||
long serverPort;
|
||||
char lastAccount[30];
|
||||
char lastPassword[30];
|
||||
} ConfigParams_t;
|
||||
|
||||
void Config_Load_Settings(ConfigParams_t* configParams);
|
||||
void Config_Save_Settings(ConfigParams_t* configParams);
|
||||
|
||||
#endif //TIBIA_CONFIG_H
|
||||
21
input.c
Normal file
21
input.c
Normal file
@ -0,0 +1,21 @@
|
||||
//
|
||||
// Created by rov on 12/26/25.
|
||||
//
|
||||
|
||||
#include "input.h"
|
||||
|
||||
#include <SDL3/SDL.h>
|
||||
|
||||
void Input_Poll(App_t *app) {
|
||||
SDL_Event event;
|
||||
|
||||
while (SDL_PollEvent(&event)) {
|
||||
switch (event.type) {
|
||||
case SDL_EVENT_QUIT:
|
||||
app->isRunning = false;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
12
input.h
Normal file
12
input.h
Normal file
@ -0,0 +1,12 @@
|
||||
//
|
||||
// Created by rov on 12/26/25.
|
||||
//
|
||||
|
||||
#ifndef TIBIA_INPUT_H
|
||||
#define TIBIA_INPUT_H
|
||||
|
||||
#include "app.h"
|
||||
|
||||
void Input_Poll(App_t* app);
|
||||
|
||||
#endif //TIBIA_INPUT_H
|
||||
11
main.c
Normal file
11
main.c
Normal file
@ -0,0 +1,11 @@
|
||||
#include "app.h"
|
||||
|
||||
int main(int argc, char* argv[]) {
|
||||
App_t app;
|
||||
|
||||
App_Init(&app);
|
||||
App_Run(&app);
|
||||
App_Shutdown(&app);
|
||||
|
||||
return 0;
|
||||
}
|
||||
14
render.c
Normal file
14
render.c
Normal file
@ -0,0 +1,14 @@
|
||||
//
|
||||
// Created by rov on 12/26/25.
|
||||
//
|
||||
|
||||
#include "render.h"
|
||||
#include "window.h"
|
||||
|
||||
void Render_Frame() {
|
||||
SDL_Renderer* renderer = Window_GetRenderer();
|
||||
SDL_SetRenderDrawColor(renderer, 0, 0, 0, 255);
|
||||
SDL_RenderClear(renderer);
|
||||
|
||||
SDL_RenderPresent(renderer);
|
||||
}
|
||||
10
render.h
Normal file
10
render.h
Normal file
@ -0,0 +1,10 @@
|
||||
//
|
||||
// Created by rov on 12/26/25.
|
||||
//
|
||||
|
||||
#ifndef TIBIA_RENDER_H
|
||||
#define TIBIA_RENDER_H
|
||||
|
||||
void Render_Frame();
|
||||
|
||||
#endif //TIBIA_RENDER_H
|
||||
24
system.c
Normal file
24
system.c
Normal file
@ -0,0 +1,24 @@
|
||||
//
|
||||
// Created by rov on 12/26/25.
|
||||
//
|
||||
|
||||
#include "system.h"
|
||||
#include <SDL3/SDL.h>
|
||||
|
||||
void System_QueryMetrics(SystemMetrics_t *systemMetrics) {
|
||||
SDL_Rect bounds;
|
||||
|
||||
const SDL_DisplayID displayId = SDL_GetPrimaryDisplay();
|
||||
if (displayId && SDL_GetDisplayBounds(displayId, &bounds)) {
|
||||
systemMetrics->screenWidth = bounds.w;
|
||||
systemMetrics->screenHeight = bounds.h;
|
||||
return;
|
||||
}
|
||||
|
||||
// Fallback
|
||||
|
||||
SDL_LogError(SDL_LOG_CATEGORY_VIDEO, "System_QueryMetrics: couldn't get primary display bounds. Using fallback values.");
|
||||
|
||||
systemMetrics->screenWidth = 800;
|
||||
systemMetrics->screenHeight = 600;
|
||||
}
|
||||
15
system.h
Normal file
15
system.h
Normal file
@ -0,0 +1,15 @@
|
||||
//
|
||||
// Created by rov on 12/26/25.
|
||||
//
|
||||
|
||||
#ifndef TIBIA_SYSTEM_H
|
||||
#define TIBIA_SYSTEM_H
|
||||
|
||||
typedef struct SystemMetrics {
|
||||
int screenWidth;
|
||||
int screenHeight;
|
||||
} SystemMetrics_t;
|
||||
|
||||
void System_QueryMetrics(SystemMetrics_t* systemMetrics);
|
||||
|
||||
#endif //TIBIA_SYSTEM_H
|
||||
24
window.c
Normal file
24
window.c
Normal file
@ -0,0 +1,24 @@
|
||||
#include "window.h"
|
||||
|
||||
static SDL_Window *window;
|
||||
static SDL_Renderer *renderer;
|
||||
|
||||
void Window_Init_SDL() {
|
||||
SDL_Init(SDL_INIT_VIDEO);
|
||||
SDL_SetHint(SDL_HINT_LOGGING, "*=info");
|
||||
}
|
||||
|
||||
void Window_Init(int width, int height) {
|
||||
SDL_CreateWindowAndRenderer(
|
||||
"Tibia", width, height, 0, &window, &renderer);
|
||||
}
|
||||
|
||||
void Window_Shutdown() {
|
||||
SDL_DestroyRenderer(renderer);
|
||||
SDL_DestroyWindow(window);
|
||||
SDL_Quit();
|
||||
}
|
||||
|
||||
SDL_Renderer *Window_GetRenderer() {
|
||||
return renderer;
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user