[Add] libxml for ship data etc.
[Fix] Memory leaks. [Fix] fixed #1 For dear old KonoM.
This commit is contained in:
parent
93fbf84c80
commit
85bec426ba
32
bin/Makefile
32
bin/Makefile
@ -1,26 +1,44 @@
|
|||||||
DEBUG = 1
|
DEBUG = 1
|
||||||
APPNAME = Lephisto
|
APPNAME = Lephisto
|
||||||
|
|
||||||
OBJ := ../src/main.o \
|
OBJS := ../src/main.o \
|
||||||
../src/physics.o \
|
../src/physics.o \
|
||||||
../src/opengl.o \
|
../src/opengl.o \
|
||||||
../src/ship.o \
|
../src/ship.o \
|
||||||
../src/pilot.o
|
../src/pilot.o
|
||||||
|
|
||||||
CFLAGS = -Wall `sdl-config --cflags`
|
CFLAGS = -Wall `sdl-config --cflags` `xml2-config --cflags`
|
||||||
ifdef DEBUG
|
ifdef DEBUG
|
||||||
CFLAGS += -g3 -DDEBUG
|
CFLAGS += -g3 -DDEBUG
|
||||||
else
|
else
|
||||||
CFLAGS += -O2
|
CFLAGS += -O2
|
||||||
endif
|
endif
|
||||||
|
|
||||||
LDFLAGS = -lm `sdl-config --libs` -lSDL_image -lGL
|
LDFLAGS = -lm `sdl-config --libs` `xml2-config --libs` -lSDL_image -lGL
|
||||||
|
|
||||||
|
DOBJS = ship.xml \
|
||||||
|
fleet.xml \
|
||||||
|
outfit.xml \
|
||||||
|
planet.xml \
|
||||||
|
ssys.xml
|
||||||
|
|
||||||
|
%.xml:
|
||||||
|
@sed -e '/^<?xml.*/d' ../dat/$@ >> data
|
||||||
|
|
||||||
%.o: ../src/%.c
|
%.o: ../src/%.c
|
||||||
gcc -c $(CFLAGS) -o $@ $<
|
@gcc -c $(CFLAGS) -o $@ $<
|
||||||
|
@echo -e "\tCC $@"
|
||||||
|
|
||||||
all: $(OBJ)
|
all: data $(OBJS)
|
||||||
gcc $(LDFLAGS) -o $(APPNAME) $(OBJ)
|
@gcc $(LDFLAGS) -o $(APPNAME) $(OBJS)
|
||||||
|
@echo -e "\tLD $(APPNAME)"
|
||||||
|
|
||||||
|
data_init:
|
||||||
|
@echo -e '<?xml version="1.0" encoding="UTF-8"?>\n<Data>' > data
|
||||||
|
|
||||||
|
data: data_init $(DOBJS)
|
||||||
|
@echo -e '</data>' >> data
|
||||||
|
@echo -e "\tCreating data\n"
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
rm -rf $(OBJ) $(APPNAME)
|
rm -rf $(OBJS) $(APPNAME)
|
||||||
|
178
bin/data
Normal file
178
bin/data
Normal file
@ -0,0 +1,178 @@
|
|||||||
|
-e <?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<Data>
|
||||||
|
<Ships>
|
||||||
|
<ship name="Ship">
|
||||||
|
<GFX>../gfx/ship.png</GFX>
|
||||||
|
<class>1</class>
|
||||||
|
<movement>
|
||||||
|
<thrust>240</thrust>
|
||||||
|
<turn>120</turn>
|
||||||
|
<speed>360</speed>
|
||||||
|
</movement>
|
||||||
|
<health>
|
||||||
|
<shield>50</shield>
|
||||||
|
<armor>80</armor>
|
||||||
|
<energy>240</energy>
|
||||||
|
<shield_regen>80</shield_regen>
|
||||||
|
<armor_regen>50</armor_regen>
|
||||||
|
<energy_regen>40</energy_regen>
|
||||||
|
</health>
|
||||||
|
<characteristics>
|
||||||
|
<crew>2</crew>
|
||||||
|
<mass>30</mass>
|
||||||
|
<cap_weapon>20</cap_weapon>
|
||||||
|
<cap_cargo>20</cap_cargo>
|
||||||
|
</caracteristics>
|
||||||
|
<outfits>
|
||||||
|
<outfit quantity='2'>laser</outfit>
|
||||||
|
</outfits>
|
||||||
|
</ship>
|
||||||
|
<ship name="Mr. Test">
|
||||||
|
<GFX>gfx/enemyship.png</GFX>
|
||||||
|
<class>1</class>
|
||||||
|
<movement>
|
||||||
|
<thrust>180</thrust>
|
||||||
|
<turn>100</turn>
|
||||||
|
<speed>260</speed>
|
||||||
|
</movement>
|
||||||
|
<health>
|
||||||
|
<shield>160</shield>
|
||||||
|
<armor>120</armor>
|
||||||
|
<energy>360</energy>
|
||||||
|
<shieldregen>90</shieldregen>
|
||||||
|
<armorregen>60</armorregen>
|
||||||
|
<energyregen>50</energyregen>
|
||||||
|
</health>
|
||||||
|
<characteristics>
|
||||||
|
<crew>9</crew>
|
||||||
|
<mass>130</mass>
|
||||||
|
<cap_weapon>60</cap_weapon>
|
||||||
|
<cap_cargo>40</cap_cargo>
|
||||||
|
</caracteristics>
|
||||||
|
<outfits>
|
||||||
|
</outfits>
|
||||||
|
</ship>
|
||||||
|
</Ships>
|
||||||
|
<Fleets>
|
||||||
|
<fleet name="Test">
|
||||||
|
<faction>2</faction>
|
||||||
|
<pilots>
|
||||||
|
<pilot chance='100'>Mr. Test</pilot>
|
||||||
|
</pilots>
|
||||||
|
</fleet>
|
||||||
|
<fleet name="Merchant Ship">
|
||||||
|
<faction>2</faction>
|
||||||
|
<pilots>
|
||||||
|
<pilot chance='100'>Ship</pilot>
|
||||||
|
</pilots>
|
||||||
|
</fleet>
|
||||||
|
<fleet name="Sml Merchant Convoy">
|
||||||
|
<faction>2</faction>
|
||||||
|
<pilots>
|
||||||
|
<pilot chance='80'>Ship</pilot>
|
||||||
|
<pilot chance='80'>Ship</pilot>
|
||||||
|
<pilot chance='60'>Ship</pilot>
|
||||||
|
<pilot chance='60'>Ship</pilot>
|
||||||
|
</pilots>
|
||||||
|
</fleet>
|
||||||
|
</Fleets>
|
||||||
|
<Outfits>
|
||||||
|
<outfit name="laser">
|
||||||
|
<general>
|
||||||
|
<max>0</max>
|
||||||
|
<type>1</type>
|
||||||
|
<tech>0</tech>
|
||||||
|
</general>
|
||||||
|
<sound>laser</sound>
|
||||||
|
<GFX>
|
||||||
|
<game>laser_green</game>
|
||||||
|
</GFX>
|
||||||
|
<parameters>
|
||||||
|
<parameter>7</parameter>
|
||||||
|
<parameter>7</parameter>
|
||||||
|
<parameter>600</parameter>
|
||||||
|
<parameter>400</parameter>
|
||||||
|
<parameter>18</parameter>
|
||||||
|
<parameter>500</parameter>
|
||||||
|
</parameters>
|
||||||
|
</outfit>
|
||||||
|
</Outfits>
|
||||||
|
<Planets>
|
||||||
|
<planet name="KonoSphere">
|
||||||
|
<pos>
|
||||||
|
<x>10</x>
|
||||||
|
<y>15</y>
|
||||||
|
</pos>
|
||||||
|
<general>
|
||||||
|
<class>1</class>
|
||||||
|
<services>1</services>
|
||||||
|
<tech>0</tech>
|
||||||
|
<commodities>1</commodities>
|
||||||
|
</general>
|
||||||
|
<GFX>KonoSphere</GFX>
|
||||||
|
</planet>
|
||||||
|
<planet name="SaraCraft">
|
||||||
|
<pos>
|
||||||
|
<x>125</x>
|
||||||
|
<y>-345</y>
|
||||||
|
</pos>
|
||||||
|
<general>
|
||||||
|
<class>1</class>
|
||||||
|
<services>1</services>
|
||||||
|
<tech>0</tech>
|
||||||
|
<commodities>1</commodities>
|
||||||
|
</general>
|
||||||
|
<GFX>SaraCraft</GFX>
|
||||||
|
</planet>
|
||||||
|
</Planets>
|
||||||
|
<Systems>
|
||||||
|
<ssys name="SaraSys">
|
||||||
|
<pos>
|
||||||
|
<x>15</x>
|
||||||
|
<y>8</y>
|
||||||
|
</pos>
|
||||||
|
<general>
|
||||||
|
<stars>50</stars>
|
||||||
|
<asteroids>0</asteroids>
|
||||||
|
<interference>0</interference>
|
||||||
|
<faction>2</faction>
|
||||||
|
</general>
|
||||||
|
<planets>
|
||||||
|
<planet>KonoSphere</planet>
|
||||||
|
</planets>
|
||||||
|
<fleets>
|
||||||
|
<fleet chance="100">Test</fleet>
|
||||||
|
<fleet chance="60">Merchant Ship</fleet>
|
||||||
|
<fleet chance="50">Merchant Ship</fleet>
|
||||||
|
<fleet chance="40">Merchant Ship</fleet>
|
||||||
|
<fleet chance="50">Sml Merchant Convoy</fleet>
|
||||||
|
<fleet chance="40">Sml Merchant Convoy</fleet>
|
||||||
|
</fleets>
|
||||||
|
<paths>
|
||||||
|
<path>KonoSys</path>
|
||||||
|
</paths>
|
||||||
|
</ssys>
|
||||||
|
<ssys name="KonoSys">
|
||||||
|
<pos>
|
||||||
|
<x>47</x>
|
||||||
|
<y>33</y>
|
||||||
|
</pos>
|
||||||
|
<general>
|
||||||
|
<stars>27</stars>
|
||||||
|
<asteroids>0</asteroids>
|
||||||
|
<interference>0</interference>
|
||||||
|
<faction>2</faction>
|
||||||
|
</general>
|
||||||
|
<planets>
|
||||||
|
<planet>SaraCraft</planet>
|
||||||
|
</planets>
|
||||||
|
<fleets>
|
||||||
|
<fleet chance="80">Merchant Ship</fleet>
|
||||||
|
<fleet chance="60">Merchant Ship</fleet>
|
||||||
|
</fleets>
|
||||||
|
<paths>
|
||||||
|
<path>SaraSys</path>
|
||||||
|
</paths>
|
||||||
|
</ssys>
|
||||||
|
</Systems>
|
||||||
|
-e </data>
|
22
dat/faction.xml
Normal file
22
dat/faction.xml
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<Factions>
|
||||||
|
<faction id='1'>
|
||||||
|
<name>Player</name>
|
||||||
|
</faction>
|
||||||
|
<faction id='2'>
|
||||||
|
<name>Noob Merchant</name>
|
||||||
|
<enemies>
|
||||||
|
<enemy>'3'</enemy>
|
||||||
|
</enemies>
|
||||||
|
<allies>
|
||||||
|
</allies>
|
||||||
|
</faction>
|
||||||
|
<faction id='3'>
|
||||||
|
<name>Pirate</name>
|
||||||
|
<enemies>
|
||||||
|
<enemy>2</enemy>
|
||||||
|
</enemies>
|
||||||
|
<allies>
|
||||||
|
</allies>
|
||||||
|
</faction>
|
||||||
|
</Factions>
|
24
dat/fleet.xml
Normal file
24
dat/fleet.xml
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<Fleets>
|
||||||
|
<fleet name="Test">
|
||||||
|
<faction>2</faction>
|
||||||
|
<pilots>
|
||||||
|
<pilot chance='100'>Mr. Test</pilot>
|
||||||
|
</pilots>
|
||||||
|
</fleet>
|
||||||
|
<fleet name="Merchant Ship">
|
||||||
|
<faction>2</faction>
|
||||||
|
<pilots>
|
||||||
|
<pilot chance='100'>Ship</pilot>
|
||||||
|
</pilots>
|
||||||
|
</fleet>
|
||||||
|
<fleet name="Sml Merchant Convoy">
|
||||||
|
<faction>2</faction>
|
||||||
|
<pilots>
|
||||||
|
<pilot chance='80'>Ship</pilot>
|
||||||
|
<pilot chance='80'>Ship</pilot>
|
||||||
|
<pilot chance='60'>Ship</pilot>
|
||||||
|
<pilot chance='60'>Ship</pilot>
|
||||||
|
</pilots>
|
||||||
|
</fleet>
|
||||||
|
</Fleets>
|
22
dat/outfit.xml
Normal file
22
dat/outfit.xml
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<Outfits>
|
||||||
|
<outfit name="laser">
|
||||||
|
<general>
|
||||||
|
<max>0</max>
|
||||||
|
<type>1</type>
|
||||||
|
<tech>0</tech>
|
||||||
|
</general>
|
||||||
|
<sound>laser</sound>
|
||||||
|
<GFX>
|
||||||
|
<game>laser_green</game>
|
||||||
|
</GFX>
|
||||||
|
<parameters>
|
||||||
|
<parameter>7</parameter>
|
||||||
|
<parameter>7</parameter>
|
||||||
|
<parameter>600</parameter>
|
||||||
|
<parameter>400</parameter>
|
||||||
|
<parameter>18</parameter>
|
||||||
|
<parameter>500</parameter>
|
||||||
|
</parameters>
|
||||||
|
</outfit>
|
||||||
|
</Outfits>
|
29
dat/planet.xml
Normal file
29
dat/planet.xml
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<Planets>
|
||||||
|
<planet name="KonoSphere">
|
||||||
|
<pos>
|
||||||
|
<x>10</x>
|
||||||
|
<y>15</y>
|
||||||
|
</pos>
|
||||||
|
<general>
|
||||||
|
<class>1</class>
|
||||||
|
<services>1</services>
|
||||||
|
<tech>0</tech>
|
||||||
|
<commodities>1</commodities>
|
||||||
|
</general>
|
||||||
|
<GFX>KonoSphere</GFX>
|
||||||
|
</planet>
|
||||||
|
<planet name="SaraCraft">
|
||||||
|
<pos>
|
||||||
|
<x>125</x>
|
||||||
|
<y>-345</y>
|
||||||
|
</pos>
|
||||||
|
<general>
|
||||||
|
<class>1</class>
|
||||||
|
<services>1</services>
|
||||||
|
<tech>0</tech>
|
||||||
|
<commodities>1</commodities>
|
||||||
|
</general>
|
||||||
|
<GFX>SaraCraft</GFX>
|
||||||
|
</planet>
|
||||||
|
</Planets>
|
54
dat/ship.xml
Normal file
54
dat/ship.xml
Normal file
@ -0,0 +1,54 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<Ships>
|
||||||
|
<ship name="Ship">
|
||||||
|
<GFX>../gfx/ship.png</GFX>
|
||||||
|
<class>1</class>
|
||||||
|
<movement>
|
||||||
|
<thrust>240</thrust>
|
||||||
|
<turn>120</turn>
|
||||||
|
<speed>360</speed>
|
||||||
|
</movement>
|
||||||
|
<health>
|
||||||
|
<shield>50</shield>
|
||||||
|
<armor>80</armor>
|
||||||
|
<energy>240</energy>
|
||||||
|
<shield_regen>80</shield_regen>
|
||||||
|
<armor_regen>50</armor_regen>
|
||||||
|
<energy_regen>40</energy_regen>
|
||||||
|
</health>
|
||||||
|
<characteristics>
|
||||||
|
<crew>2</crew>
|
||||||
|
<mass>30</mass>
|
||||||
|
<cap_weapon>20</cap_weapon>
|
||||||
|
<cap_cargo>20</cap_cargo>
|
||||||
|
</caracteristics>
|
||||||
|
<outfits>
|
||||||
|
<outfit quantity='2'>laser</outfit>
|
||||||
|
</outfits>
|
||||||
|
</ship>
|
||||||
|
<ship name="Mr. Test">
|
||||||
|
<GFX>gfx/enemyship.png</GFX>
|
||||||
|
<class>1</class>
|
||||||
|
<movement>
|
||||||
|
<thrust>180</thrust>
|
||||||
|
<turn>100</turn>
|
||||||
|
<speed>260</speed>
|
||||||
|
</movement>
|
||||||
|
<health>
|
||||||
|
<shield>160</shield>
|
||||||
|
<armor>120</armor>
|
||||||
|
<energy>360</energy>
|
||||||
|
<shieldregen>90</shieldregen>
|
||||||
|
<armorregen>60</armorregen>
|
||||||
|
<energyregen>50</energyregen>
|
||||||
|
</health>
|
||||||
|
<characteristics>
|
||||||
|
<crew>9</crew>
|
||||||
|
<mass>130</mass>
|
||||||
|
<cap_weapon>60</cap_weapon>
|
||||||
|
<cap_cargo>40</cap_cargo>
|
||||||
|
</caracteristics>
|
||||||
|
<outfits>
|
||||||
|
</outfits>
|
||||||
|
</ship>
|
||||||
|
</Ships>
|
51
dat/ssys.xml
Normal file
51
dat/ssys.xml
Normal file
@ -0,0 +1,51 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<Systems>
|
||||||
|
<ssys name="SaraSys">
|
||||||
|
<pos>
|
||||||
|
<x>15</x>
|
||||||
|
<y>8</y>
|
||||||
|
</pos>
|
||||||
|
<general>
|
||||||
|
<stars>50</stars>
|
||||||
|
<asteroids>0</asteroids>
|
||||||
|
<interference>0</interference>
|
||||||
|
<faction>2</faction>
|
||||||
|
</general>
|
||||||
|
<planets>
|
||||||
|
<planet>KonoSphere</planet>
|
||||||
|
</planets>
|
||||||
|
<fleets>
|
||||||
|
<fleet chance="100">Test</fleet>
|
||||||
|
<fleet chance="60">Merchant Ship</fleet>
|
||||||
|
<fleet chance="50">Merchant Ship</fleet>
|
||||||
|
<fleet chance="40">Merchant Ship</fleet>
|
||||||
|
<fleet chance="50">Sml Merchant Convoy</fleet>
|
||||||
|
<fleet chance="40">Sml Merchant Convoy</fleet>
|
||||||
|
</fleets>
|
||||||
|
<paths>
|
||||||
|
<path>KonoSys</path>
|
||||||
|
</paths>
|
||||||
|
</ssys>
|
||||||
|
<ssys name="KonoSys">
|
||||||
|
<pos>
|
||||||
|
<x>47</x>
|
||||||
|
<y>33</y>
|
||||||
|
</pos>
|
||||||
|
<general>
|
||||||
|
<stars>27</stars>
|
||||||
|
<asteroids>0</asteroids>
|
||||||
|
<interference>0</interference>
|
||||||
|
<faction>2</faction>
|
||||||
|
</general>
|
||||||
|
<planets>
|
||||||
|
<planet>SaraCraft</planet>
|
||||||
|
</planets>
|
||||||
|
<fleets>
|
||||||
|
<fleet chance="80">Merchant Ship</fleet>
|
||||||
|
<fleet chance="60">Merchant Ship</fleet>
|
||||||
|
</fleets>
|
||||||
|
<paths>
|
||||||
|
<path>SaraSys</path>
|
||||||
|
</paths>
|
||||||
|
</ssys>
|
||||||
|
</Systems>
|
BIN
gfx/enemyship.png
Normal file
BIN
gfx/enemyship.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 145 KiB |
@ -1,6 +1,9 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#define MALLOC_L(type)(malloc(sizeof(type)))
|
#define MALLOC_L(type)(malloc(sizeof(type)))
|
||||||
|
#define CALLOC_L(type)(calloc(1, sizeof(type)))
|
||||||
|
|
||||||
typedef float FP;
|
typedef float FP;
|
||||||
|
|
||||||
|
#define DATA "data"
|
||||||
|
|
||||||
|
@ -1,8 +1,9 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
#include <SDL.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
||||||
#define LOG(str, args...)(fprintf(stdout, str"\n", ## args))
|
#define LOG(str, args...)(fprintf(stdout, str"\n", ## args))
|
||||||
#define WARN(str, args...)(fprintf(stderr, "[%d] "str"\n", 0, ## args))
|
#define WARN(str, args...)(fprintf(stderr, "[%d] "str"\n", SDL_GetTicks(), ## args))
|
||||||
|
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
# undef DEBUG
|
# undef DEBUG
|
||||||
|
125
src/main.c
125
src/main.c
@ -10,86 +10,77 @@
|
|||||||
#include "ship.h"
|
#include "ship.h"
|
||||||
#include "pilot.h"
|
#include "pilot.h"
|
||||||
|
|
||||||
|
static int quit = 0;
|
||||||
|
|
||||||
|
// Prototypes.
|
||||||
|
static void handle_keydown(SDLKey key);
|
||||||
|
static void handle_keyup(SDLKey key);
|
||||||
|
|
||||||
|
// Update.
|
||||||
|
static void update_all(void);
|
||||||
|
|
||||||
int main(int argc, const char** argv) {
|
int main(int argc, const char** argv) {
|
||||||
int quit = 0;
|
|
||||||
SDL_Event event;
|
SDL_Event event;
|
||||||
|
|
||||||
|
// Default window params.
|
||||||
gl_screen.w = 800;
|
gl_screen.w = 800;
|
||||||
gl_screen.h = 640;
|
gl_screen.h = 640;
|
||||||
gl_screen.fullscreen = 0;
|
gl_screen.fullscreen = 0;
|
||||||
|
if(gl_init()) {
|
||||||
gl_init();
|
// Initializes video output.
|
||||||
|
WARN("Error initializing video output, exiting...");
|
||||||
gl_texture* tex;
|
exit(EXIT_FAILURE);
|
||||||
if((tex = gl_newSprite("../gfx/ship.png", 6, 6)) == NULL) {
|
|
||||||
WARN("Unable to load image");
|
|
||||||
return -1;
|
|
||||||
}
|
}
|
||||||
Ship* ship = MALLOC_L(Ship);
|
|
||||||
ship->gfx_ship = tex;
|
|
||||||
ship->mass = 1;
|
|
||||||
ship->class = SHIP_CLASS_CIVILIAN;
|
|
||||||
Pilot* player = pilot_create(ship, "player", NULL, NULL, PILOT_PLAYER);
|
|
||||||
gl_bindCamera(&player->solid->pos);
|
|
||||||
|
|
||||||
int tflag = 0;
|
// Data loading.
|
||||||
unsigned int time = SDL_GetTicks();
|
ships_load();
|
||||||
FP dt;
|
|
||||||
|
// Main looops.
|
||||||
while(!quit) {
|
while(!quit) {
|
||||||
|
// Event loop.
|
||||||
while(SDL_PollEvent(&event)) {
|
while(SDL_PollEvent(&event)) {
|
||||||
switch(event.type) {
|
switch(event.type) {
|
||||||
case SDL_KEYDOWN:
|
case SDL_KEYDOWN:
|
||||||
switch(event.key.keysym.sym) {
|
handle_keydown(event.key.keysym.sym);
|
||||||
case SDLK_ESCAPE:
|
break;
|
||||||
quit = 1;
|
case SDL_KEYUP:
|
||||||
break;
|
handle_keyup(event.key.keysym.sym);
|
||||||
case SDLK_a:
|
break;
|
||||||
tflag ^= 1;
|
case SDL_QUIT:
|
||||||
break;
|
quit = 1;
|
||||||
case SDLK_d:
|
break;
|
||||||
tflag ^=2;
|
|
||||||
case SDLK_w:
|
|
||||||
tflag ^= 8;
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case SDL_KEYUP:
|
|
||||||
switch(event.key.keysym.sym) {
|
|
||||||
case SDLK_a:
|
|
||||||
tflag ^= 1;
|
|
||||||
break;
|
|
||||||
case SDLK_d:
|
|
||||||
tflag ^= 2;
|
|
||||||
break;
|
|
||||||
case SDLK_w:
|
|
||||||
tflag ^= 8;
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
dt = (FP)(SDL_GetTicks() - time) / 1000.0;
|
update_all();
|
||||||
if(tflag & 1) player->solid->dir += 200.0 / 180.0*M_PI*dt;
|
|
||||||
if(tflag & 2) player->solid->dir -= 200.0 / 180.0*M_PI*dt;
|
|
||||||
if(tflag & 8) player->solid->force = 340;
|
|
||||||
else player->solid->force = 0;
|
|
||||||
glClear(GL_COLOR_BUFFER_BIT);
|
|
||||||
player->update(player, dt);
|
|
||||||
SDL_GL_SwapBuffers();
|
|
||||||
time = SDL_GetTicks();
|
|
||||||
SDL_Delay(5);
|
|
||||||
}
|
}
|
||||||
|
// Unload data.
|
||||||
pilot_free(player);
|
ships_free();
|
||||||
free(ship);
|
gl_exit(); // Kills video output.
|
||||||
gl_free(tex);
|
exit(EXIT_SUCCESS);
|
||||||
|
}
|
||||||
gl_exit();
|
|
||||||
|
// Handle keydown events.
|
||||||
return 0;
|
static void handle_keydown(SDLKey key) {
|
||||||
|
switch(key) {
|
||||||
|
case SDLK_ESCAPE:
|
||||||
|
quit = 1;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Handle keyup events.
|
||||||
|
static void handle_keyup(SDLKey key) {
|
||||||
|
switch(key) {
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Update all the things.
|
||||||
|
static void update_all(void) {
|
||||||
|
glClear(GL_COLOR_BUFFER_BIT);
|
||||||
|
SDL_GL_SwapBuffers();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
24
src/opengl.c
24
src/opengl.c
@ -62,18 +62,21 @@ gl_texture* gl_newImage(const char* path) {
|
|||||||
tmp = IMG_Load(path); // Load the surface.
|
tmp = IMG_Load(path); // Load the surface.
|
||||||
if(tmp == 0) {
|
if(tmp == 0) {
|
||||||
WARN("'%s' could not be opened: %s", path, IMG_GetError());
|
WARN("'%s' could not be opened: %s", path, IMG_GetError());
|
||||||
return 0;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
surface = SDL_DisplayFormatAlpha(tmp); // Set the surface to what we use.
|
surface = SDL_DisplayFormatAlpha(tmp); // Set the surface to what we use.
|
||||||
if(surface == 0) {
|
if(surface == 0) {
|
||||||
WARN("Error converting image to screen format: %s", SDL_GetError());
|
WARN("Error converting image to screen format: %s", SDL_GetError());
|
||||||
return 0;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
SDL_FreeSurface(tmp); // Free the temp surface.
|
SDL_FreeSurface(tmp); // Free the temp surface.
|
||||||
|
|
||||||
flip_surface(surface);
|
if(flip_surface(surface)) {
|
||||||
|
WARN("Error flipping surface");
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
// Set up the texture defaults.
|
// Set up the texture defaults.
|
||||||
gl_texture* texture = MALLOC_L(gl_texture);
|
gl_texture* texture = MALLOC_L(gl_texture);
|
||||||
@ -117,11 +120,11 @@ gl_texture* gl_newImage(const char* path) {
|
|||||||
texture->rw, texture->rh, surface->format->BytesPerPixel*8, RGBMASK);
|
texture->rw, texture->rh, surface->format->BytesPerPixel*8, RGBMASK);
|
||||||
if(tmp == NULL) {
|
if(tmp == NULL) {
|
||||||
WARN("Unable to create POT surface %s", SDL_GetError());
|
WARN("Unable to create POT surface %s", SDL_GetError());
|
||||||
return 0;
|
return NULL;
|
||||||
}
|
}
|
||||||
if(SDL_FillRect(tmp, NULL, SDL_MapRGBA(surface->format, 0, 0, 0, SDL_ALPHA_TRANSPARENT))) {
|
if(SDL_FillRect(tmp, NULL, SDL_MapRGBA(surface->format, 0, 0, 0, SDL_ALPHA_TRANSPARENT))) {
|
||||||
WARN("Unable to fill rect: %s", SDL_GetError());
|
WARN("Unable to fill rect: %s", SDL_GetError());
|
||||||
return 0;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
SDL_BlitSurface(surface, &rtemp, tmp, &rtemp);
|
SDL_BlitSurface(surface, &rtemp, tmp, &rtemp);
|
||||||
@ -181,8 +184,8 @@ void gl_blitSprite(gl_texture* sprite, Vec2* pos, const int sx, const int sy) {
|
|||||||
|
|
||||||
glMatrixMode(GL_PROJECTION);
|
glMatrixMode(GL_PROJECTION);
|
||||||
glPushMatrix(); // Projection translation matrix.
|
glPushMatrix(); // Projection translation matrix.
|
||||||
glTranslatef(gl_camera->x - pos->x - sprite->sw / 2.0,
|
glTranslatef(pos->x - gl_camera->x - sprite->sw/2.0,
|
||||||
gl_camera->y - pos->y - sprite->sh/2.0, 0.0f);
|
pos->y - gl_camera->y - sprite->sh/2.0, 0.0f);
|
||||||
|
|
||||||
// Actual blitting....
|
// Actual blitting....
|
||||||
glBindTexture(GL_TEXTURE_2D, sprite->texture);
|
glBindTexture(GL_TEXTURE_2D, sprite->texture);
|
||||||
@ -204,7 +207,7 @@ void gl_blitSprite(gl_texture* sprite, Vec2* pos, const int sx, const int sy) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Just straight out blit the thing at position.
|
// Just straight out blit the thing at position.
|
||||||
void gl_blit(gl_texture* texture, Vec2* pos) {
|
void gl_blitStatic(gl_texture* texture, Vec2* pos) {
|
||||||
glMatrixMode(GL_PROJECTION);
|
glMatrixMode(GL_PROJECTION);
|
||||||
glPushMatrix(); // Set up translation matrix.
|
glPushMatrix(); // Set up translation matrix.
|
||||||
glTranslatef(pos->x, pos->y, 0);
|
glTranslatef(pos->x, pos->y, 0);
|
||||||
@ -242,7 +245,8 @@ int gl_init(void) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// FFUUUU Ugly cursor thing.
|
// FFUUUU Ugly cursor thing.
|
||||||
SDL_ShowCursor(SDL_DISABLE);
|
// -- Ok, Maybe for now.
|
||||||
|
//SDL_ShowCursor(SDL_DISABLE);
|
||||||
|
|
||||||
flags |= SDL_FULLSCREEN* gl_screen.fullscreen;
|
flags |= SDL_FULLSCREEN* gl_screen.fullscreen;
|
||||||
depth = SDL_VideoModeOK(gl_screen.w, gl_screen.h, gl_screen.depth, flags); // Test set up.
|
depth = SDL_VideoModeOK(gl_screen.w, gl_screen.h, gl_screen.depth, flags); // Test set up.
|
||||||
@ -297,7 +301,7 @@ int gl_init(void) {
|
|||||||
|
|
||||||
// Clean up our mess.
|
// Clean up our mess.
|
||||||
void gl_exit(void) {
|
void gl_exit(void) {
|
||||||
SDL_ShowCursor(SDL_ENABLE);
|
//SDL_ShowCursor(SDL_ENABLE);
|
||||||
SDL_Quit();
|
SDL_Quit();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -31,7 +31,7 @@ void gl_free(gl_texture* texture);
|
|||||||
|
|
||||||
// Rendering.
|
// Rendering.
|
||||||
void gl_blitSprite(gl_texture* sprite, Vec2* pos, const int sx, const int sy);
|
void gl_blitSprite(gl_texture* sprite, Vec2* pos, const int sx, const int sy);
|
||||||
void gl_blit(gl_texture* texture, Vec2* pos);
|
void gl_blitStatic(gl_texture* texture, Vec2* pos);
|
||||||
void gl_bindCamera(Vec2* pos);
|
void gl_bindCamera(Vec2* pos);
|
||||||
|
|
||||||
// Initialize/cleanup.
|
// Initialize/cleanup.
|
||||||
|
@ -6,6 +6,9 @@
|
|||||||
// Stack of pilot id's to assure uniqueness.
|
// Stack of pilot id's to assure uniqueness.
|
||||||
static unsigned int pilot_id = 0;
|
static unsigned int pilot_id = 0;
|
||||||
|
|
||||||
|
// Stack of pilots - yes, they come in stacks now.
|
||||||
|
static Pilot* pilot_stack = NULL;
|
||||||
|
|
||||||
static void pilot_update(Pilot* pilot, const FP dt);
|
static void pilot_update(Pilot* pilot, const FP dt);
|
||||||
static void pilot_render(Pilot* pilot);
|
static void pilot_render(Pilot* pilot);
|
||||||
|
|
||||||
|
@ -6,6 +6,7 @@
|
|||||||
#define PILOT_PLAYER 1 // Pilot is a player.
|
#define PILOT_PLAYER 1 // Pilot is a player.
|
||||||
|
|
||||||
struct Pilot {
|
struct Pilot {
|
||||||
|
struct Pilot* next;
|
||||||
int id; // Pilot's id.
|
int id; // Pilot's id.
|
||||||
char* name; // Pilot's name (if unique).
|
char* name; // Pilot's name (if unique).
|
||||||
|
|
||||||
|
138
src/ship.c
138
src/ship.c
@ -1,2 +1,140 @@
|
|||||||
|
#include <string.h>
|
||||||
|
#include "libxml/xmlreader.h"
|
||||||
|
|
||||||
|
#include "log.h"
|
||||||
#include "ship.h"
|
#include "ship.h"
|
||||||
|
|
||||||
|
#define XML_NODE_START 1
|
||||||
|
#define XML_NODE_TEXT 3
|
||||||
|
#define XML_NODE_CLOSE 15
|
||||||
|
#define XML_NODE_CDATA 4
|
||||||
|
|
||||||
|
#define XML_ID "Ships" // XML section identifier.
|
||||||
|
#define XML_SHIP "ship"
|
||||||
|
|
||||||
|
static Ship* ship_stack = NULL;
|
||||||
|
static int ships;
|
||||||
|
|
||||||
|
// Get a ship based on it's name.
|
||||||
|
Ship* get_ship(const char* name) {
|
||||||
|
Ship* tmp = ship_stack;
|
||||||
|
while(tmp != NULL)
|
||||||
|
if(strcmp((tmp++)->name, name)==0) break;
|
||||||
|
|
||||||
|
return tmp;
|
||||||
|
}
|
||||||
|
|
||||||
|
Ship* ship_parse(xmlNodePtr node) {
|
||||||
|
xmlNodePtr cur;
|
||||||
|
Ship* tmp = CALLOC_L(Ship);
|
||||||
|
|
||||||
|
tmp->name = (char*)xmlGetProp(node, (xmlChar*)"name");
|
||||||
|
|
||||||
|
node = node->xmlChildrenNode;
|
||||||
|
|
||||||
|
while((node = node->next)) {
|
||||||
|
if(strcmp((char*)node->name, "GFX")==0) {
|
||||||
|
cur = node->children;
|
||||||
|
if(strcmp((char*)cur->name, "text")==0)
|
||||||
|
tmp->gfx_ship = gl_newSprite((char*)cur->content, 6, 6);
|
||||||
|
}
|
||||||
|
else if(strcmp((char*)node->name, "class")==0) {
|
||||||
|
cur = node->children;
|
||||||
|
if(strcmp((char*)cur->name, "text")==0)
|
||||||
|
tmp->class = atoi((char*)cur->content);
|
||||||
|
}
|
||||||
|
else if(strcmp((char*)node->name, "movement")==0) {
|
||||||
|
cur = node->children;
|
||||||
|
while((cur = cur->next)) {
|
||||||
|
if(strcmp((char*)cur->name, "thrust")==0)
|
||||||
|
tmp->thrust = atoi((char*)cur->children->content);
|
||||||
|
else if(strcmp((char*)cur->name, "turn")==0)
|
||||||
|
tmp->turn = atoi((char*)cur->children->content);
|
||||||
|
else if(strcmp((char*)cur->name, "speed")==0)
|
||||||
|
tmp->speed = atoi((char*)cur->children->content);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if(strcmp((char*)node->name, "health")==0) {
|
||||||
|
cur = node->children;
|
||||||
|
while((cur = cur->next)) {
|
||||||
|
if(strcmp((char*)cur->name, "armor")==0)
|
||||||
|
tmp->armor = (FP)atoi((char*)cur->children->content);
|
||||||
|
else if(strcmp((char*)cur->name, "shield")==0)
|
||||||
|
tmp->shield = (FP)atoi((char*)cur->children->content);
|
||||||
|
else if(strcmp((char*)cur->name, "energy")==0)
|
||||||
|
tmp->energy = (FP)atoi((char*)cur->children->content);
|
||||||
|
else if(strcmp((char*)cur->name, "armor_regen")==0)
|
||||||
|
tmp->armor_regen = (FP)(atoi((char*)cur->children->content))/60.0;
|
||||||
|
else if(strcmp((char*)cur->name, "shield_regen")==0)
|
||||||
|
tmp->shield_regen = (FP)(atoi((char*)cur->children->content))/60.0;
|
||||||
|
else if(strcmp((char*)cur->name, "energy_regen")==0)
|
||||||
|
tmp->energy_regen = (FP)(atoi((char*)cur->children->content))/60.0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if(strcmp((char*)node->name, "characteristics")==0) {
|
||||||
|
cur = node->children;
|
||||||
|
while((cur = cur->next)) {
|
||||||
|
if(strcmp((char*)cur->name, "crew")==0)
|
||||||
|
tmp->crew = atoi((char*)cur->children->content);
|
||||||
|
else if(strcmp((char*)cur->name, "mass")==0)
|
||||||
|
tmp->mass = (FP)atoi((char*)cur->children->content);
|
||||||
|
else if(strcmp((char*)cur->name, "cap_weapon")==0)
|
||||||
|
tmp->cap_weapon = atoi((char*)cur->children->content);
|
||||||
|
else if(strcmp((char*)cur->name, "cap_cargo")==0)
|
||||||
|
tmp->cap_cargo = atoi((char*)cur->children->content);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
DEBUG("Loaded ship '%s'", tmp->name);
|
||||||
|
return tmp;
|
||||||
|
}
|
||||||
|
|
||||||
|
int ships_load(void) {
|
||||||
|
xmlTextReaderPtr reader;
|
||||||
|
xmlNodePtr node;
|
||||||
|
Ship* tmp = NULL;
|
||||||
|
|
||||||
|
if((reader == xmlNewTextReaderFilename(DATA)) == NULL) {
|
||||||
|
WARN("XML error reading " DATA);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get to the start of the "ships" section.
|
||||||
|
while(xmlTextReaderRead(reader)==1) {
|
||||||
|
if(xmlTextReaderNodeType(reader)==XML_NODE_START &&
|
||||||
|
strcmp((char*)xmlTextReaderConstName(reader), XML_ID) == 0) break;
|
||||||
|
}
|
||||||
|
|
||||||
|
xmlTextReaderRead(reader); // At ships node.
|
||||||
|
|
||||||
|
while(xmlTextReaderRead(reader)==1) {
|
||||||
|
if(xmlTextReaderNodeType(reader)==XML_NODE_START &&
|
||||||
|
strcmp((char*)xmlTextReaderConstName(reader), XML_SHIP)==0) {
|
||||||
|
|
||||||
|
node = xmlTextReaderCurrentNode(reader); // Node to process.
|
||||||
|
if(ship_stack == NULL) {
|
||||||
|
ship_stack = tmp = ship_parse(node);
|
||||||
|
ships = 1;
|
||||||
|
} else {
|
||||||
|
tmp = ship_parse(node);
|
||||||
|
ship_stack = realloc(ship_stack, sizeof(Ship)*(++ships));
|
||||||
|
memcpy(ship_stack+ships-1, tmp, sizeof(Ship));
|
||||||
|
free(tmp);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
xmlFreeTextReader(reader);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
void ships_free(void) {
|
||||||
|
int i;
|
||||||
|
for(i = 0; i < ships; i++) {
|
||||||
|
if((ship_stack+i)->name)
|
||||||
|
free((ship_stack+i)->name);
|
||||||
|
gl_free((ship_stack+i)->gfx_ship);
|
||||||
|
}
|
||||||
|
free(ship_stack);
|
||||||
|
ship_stack = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
@ -28,3 +28,8 @@ typedef struct {
|
|||||||
int cap_cargo, cap_weapon;
|
int cap_cargo, cap_weapon;
|
||||||
} Ship;
|
} Ship;
|
||||||
|
|
||||||
|
int ships_load(void);
|
||||||
|
void ships_free(void);
|
||||||
|
|
||||||
|
Ship* get_ship(const char* name);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user